llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.71k stars 11.88k forks source link

C++ compile-time array bounds unsuccessfully inferred from template expansions #113936

Open mld2443 opened 3 hours ago

mld2443 commented 3 hours ago

https://compiler-explorer.com/z/33Yhbxdoc

template <int... VALUES>
struct C {
    static constexpr int VALUEARRAY[] = {VALUES...};
};

static_assert(C<0,1,2,3,4>::VALUEARRAY[4] == 4);

clang needs the hint of sizeof...(VALUES) to build correctly

tbaederr commented 2 hours ago

The AST node is:

`-DeclRefExpr 0x7e0f6b8bcfd0 'const int[]' lvalue Var 0x7e0f6b8bca28 'VALUEARRAY' 'const int[5]' non_odr_use_constant
  `-NestedNameSpecifier TypeSpec 'C<0, 1, 2, 3, 4>':'struct C<0, 1, 2, 3, 4>'

But the type of the expression is an IncompleteArrayType.

llvmbot commented 2 hours ago

@llvm/issue-subscribers-clang-frontend

Author: Matt (mld2443)

https://compiler-explorer.com/z/33Yhbxdoc ```cpp template <int... VALUES> struct C { static constexpr int VALUEARRAY[] = {VALUES...}; }; static_assert(C<0,1,2,3,4>::VALUEARRAY[4] == 4); ``` clang needs the hint of `sizeof...(VALUES)` to build correctly