[Bug c++/126825] New: Array decays to pointer when constructing element of std::initializer_list

"eczbek.void at gmail dot com via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126825

            Bug ID: 126825
           Summary: Array decays to pointer when constructing element of
                    std::initializer_list
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eczbek.void at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/oKWWEToaf
Clang accepts this.
```
struct A {
        template<typename T>
        A(T& arg) {
                static_assert(std::is_same_v<T, const char[1]>);
        }
};

int main() {
        std::initializer_list<A> { "" };
}
```

```
<source>: In instantiation of 'A::A(T&) [with T = const char* const]':
<source>:12:32:   required from here
   12 |         std::initializer_list<A> { "" };
      |                                       ^
<source>:7:36: error: static assertion failed
    7 |                 static_assert(std::is_same_v<T, const char[1]>);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 'const char* const' is not the same as 'const char [1]'
```
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.