https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96268

            Bug ID: 96268
           Summary: class-type NTTP CTAD for string-literal aggregate
                    fails on aggregate initialization
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wjwray at gmail dot com
  Target Milestone: ---

I understand that gcc is ahead of the standard in its implementation of class-
type NTTP, along with CTAD and accepting braced init-lists as template Args.
Thanks for implementing it. This bug is an edge case in the handling of a
braced string literal argument for a 'static string' - a motivating use case. 

Example code on Compiler Explorer https://godbolt.org/z/sMWhbx

Given this 'static_string' implementation, as an aggregate (no constructors):

  template <int N>
  struct static_string { char chars[N]; /* operator<=> */ };

  template <int N>
  static_string(char const(&)[N]) -> static_string<N>;

A variable can be deduced and initialized from braced string-literal:

  static_string hi = {"hi"}; // Accepted

(Aggregate-init of char array from string-literal being a special case.)
However, this same braced string-literal fails as a class-type NTTP:

  template <static_string str> struct name {};

  using Hi = name<{"hi"}>; // Reject, should accept?

It appears to CTAD-deduce correctly then fail on the aggregate initialization:

  error: could not convert '{"hi"}' from '<brace-enclosed init list>
                                      to 'static_string<3>'
  | name<{"hi"}>;
  |            ^
  |            |
  |            <brace-enclosed initializer list>

Reply via email to