Skip to content

Clang compiles valid (?) program incorrectlyΒ #105643

@socketpair

Description

@socketpair

https://godbolt.org/z/z4szqa4rT

#include <iostream>
#include <string>
using namespace std;

namespace {

template <class T>
consteval const char* type2str() = delete;

template <>
consteval const char* type2str<int>() {
    return "int";
};

template <typename T, const char* Name>
consteval const char* fun() {
    static constexpr auto mmm = string(type2str<T>()) + " " + Name + "\x00";
    return mmm.data();
}

}  // namespace

int main() {
    static constexpr char ZZZ[]{"qwe"}; // changing constexpr => const makes clang fail to compile (gcc eats both cases normally)

    cout << fun<int, ZZZ>();

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"miscompilationneeds-reductionLarge reproducer that should be reduced into a simpler form

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions