[Bug c++/67259] New: list-initialization of a reference fails to initialize char array from string literal

cubbi at cubbi dot org gcc-bugzilla@gcc.gnu.org
Tue Aug 18 16:22:00 GMT 2015


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

            Bug ID: 67259
           Summary: list-initialization of a reference fails to initialize
                    char array from string literal
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cubbi at cubbi dot org
  Target Milestone: ---

The following is accepted by clang, intel, and msvc, but fails to compile with
gcc (HEAD 6.0.0 20150817)

struct agg { char str[20]; };
int main() {
    const agg& r {"foo"};
}

with the following diagnostic:

prog.cc: In function 'int main()':
prog.cc:3:24: error: invalid initialization of reference of type 'const agg&'
from expression of type '<brace-enclosed initializer list>'
     const agg& r {"foo"};
                        ^
prog.cc:3:16: warning: unused variable 'r' [-Wunused-variable]
     const agg& r {"foo"};
                ^
(this also prevents agg x; x = { "foo" };)

it appears to be one of the consequences of the changes to list initialization
recently made by http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1467



More information about the Gcc-bugs mailing list