Open llvmbot opened 7 years ago
gcc prints out 2.
I think this is related to llvm/llvm-project#32549 .
It looks like clang doesn't seem to be able to deduce the size of constexpr static arrays in a template class.
This bug still exists in post 17 trunk(a1358225c5b791fa9d901e74fb09606189c0e6af) https://godbolt.org/z/qb9MMEMd3
simplified code which fails compilation instead of at runtime
template <int C>
struct foo
{
static int constexpr f[] = { C, 0 };
static_assert(std::extent<decltype(f)>::value);
};
int main()
{
foo<1> f;
}
compile error
<source>:7:19: error: static assertion failed due to requirement 'std::extent<const int[], 0>::value'
7 | static_assert(std::extent<decltype(f)>::value);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:12:12: note: in instantiation of template class 'foo<1>' requested here
12 | foo<1> f;
| ^
1 error generated.
Compiler returned: 1
gcc 13.2 compiles fine
@llvm/issue-subscribers-clang-frontend
Author: None (llvmbot)
Extended Description
include
include
template <char ...C> struct ConstantCharsToString { static const char constexpr str[] = { C..., '\0' }; ConstantCharsToString() { printf("%ld\n", std::extent<decltype(str)>::value); } };
int main() { ConstantCharsToString<'h'> foo; }
[razeh@rdx-ws-001 scratch]$ clang++ foo.C -std=c++1z [razeh@rdx-ws-001 scratch]$ ./a.out 0
I was hoping for a 2. clang version 5.0.0 (trunk 298852) (llvm/trunk 298851) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /scratch/razeh/apps/clang-4.0/bin [razeh@rdx-ws-001 scratch]$