Issue 150426
Summary extent_v in static_assert not detecting inferred array length with rest argument expansion before use
Labels new issue
Assignees
Reporter mstange
    https://godbolt.org/z/c61WhKbaz

The `static_assert` below fails in clang 20.1.0, but passes in gcc 15.1 and msvc 19:

```cpp
#include <stdio.h>
#include <type_traits>

template <int... ArgValues>
struct MyTemplateStruct {
    static constexpr int values[] = {ArgValues...};
};

int main() {
    using ConcreteStruct = MyTemplateStruct<5>;

    // printf("test: %d\n", ConcreteStruct::values[0]);

    // This assertion starts passing if you uncomment the above printf
 static_assert(std::extent_v<decltype(ConcreteStruct::values)> == 1,
 "should detect one element in values member");

    return 0;
}
```

Error message with clang:

```
<source>:15:19: error: static assertion failed due to requirement 'std::extent_v<const int[], 0> == 1': should detect one element in values member
   15 | static_assert(std::extent_v<decltype(ConcreteStruct::values)> == 1,
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:15:67: note: _expression_ evaluates to '0 == 1'
   15 | static_assert(std::extent_v<decltype(ConcreteStruct::values)> == 1,
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
1 error generated.
```

The first template argument to `extent_v` is `const int[]` without the printf, and `const int[1]` with the printf.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to