This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67259] New: list-initialization of a reference fails to initialize char array from string literal
- From: "cubbi at cubbi dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 18 Aug 2015 16:22:31 +0000
- Subject: [Bug c++/67259] New: list-initialization of a reference fails to initialize char array from string literal
- Auto-submitted: auto-generated
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