Reputation: 263
template<int const * pci> struct X {};
extern int const ai[];
X<ai> xi;
int const ai[] = {0,1,2,3};
If I try to compile this code with "clang++ -std=c++1z" it result in error:
test.cpp:4:3: error: non-type template argument refers to subobject '&ai'
But it isn't subobject.
http://en.cppreference.com/w/cpp/language/template_parameters doesn't list any suitable limitation for extern arrays in '(since C++17)' section for non-type arguments.
Such code works fine with -std=c++14. And GCC also compiles it without errors in c++1z mode: https://godbolt.org/g/K9wZ4g
Is it a clang bug? Or is this code wrong?
Upvotes: 4
Views: 781
Reputation: 156
Yes, it's a clang bug, confirmed by clang developer and has been fixed in trunk (r311970). http://lists.llvm.org/pipermail/cfe-dev/2017-August/055249.html
Meanwhile, to work around it, you need to write the length of array in the declaration explicitly.
extern int const ai[4];
Upvotes: 3