Lỗi extended initializer lists only available with or năm 2024

Test #{{ $caseIndex + 1 }}

Điểm: {{ Math.trunc(curCase.result.scoringRate * 100) }}

Thời gian chạy: {{ curCase.result.time }} ms

Bộ nhớ: {{ curCase.result.memory }} KiB

Craig Schroeder 2013-07-21 03:28:19 UTC

Program: template <class _E> class initializer_list {}; template <int N> struct D {D(std::initializer_list<int>) {}}; D<0> d{1, 2, 3}; Compile like this: g++ prog.cpp Output: prog.cpp:8:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]

   D<0> d{
        ^
prog.cpp:9:11: error: in C++98 ‘std::d’ must be initialized by constructor, not by ‘{...}’
1, 2, 3};
       ^
prog.cpp:9:11: internal compiler error: Segmentation fault 0xaac4cf crash_signal ../../s-4.9/gcc/toplev.c:333 0x519ce3 contains_struct_check ../../s-4.9/gcc/tree.h:3803 0x519ce3 convert_like_real ../../s-4.9/gcc/cp/call.c:6055 0x51b671 build_over_call ../../s-4.9/gcc/cp/call.c:6943 0x517b3b build_new_method_call_1 ../../s-4.9/gcc/cp/call.c:7777 0x517b3b build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>, tree_node*, int, tree_node, int) ../../s-4.9/gcc/cp/call.c:7847 0x518d12 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>, tree_node*, int, int) ../../s-4.9/gcc/cp/call.c:7412 0x6657d7 expand_default_init ../../s-4.9/gcc/cp/init.c:1664 0x6657d7 expand_aggr_init_1 ../../s-4.9/gcc/cp/init.c:1765 0x66835a build_aggr_init(tree_node*, tree_node*, int, int) ../../s-4.9/gcc/cp/init.c:1516 0x52d01d build_aggr_init_full_exprs ../../s-4.9/gcc/cp/decl.c:5545 0x52d01d check_initializer ../../s-4.9/gcc/cp/decl.c:5680 0x54006d cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) ../../s-4.9/gcc/cp/decl.c:6349 0x6260fd cp_parser_init_declarator ../../s-4.9/gcc/cp/parser.c:16527 0x62673e cp_parser_simple_declaration ../../s-4.9/gcc/cp/parser.c:10946 0x6285a0 cp_parser_block_declaration ../../s-4.9/gcc/cp/parser.c:10827 0x63160b cp_parser_declaration ../../s-4.9/gcc/cp/parser.c:10724 0x6302dd cp_parser_declaration_seq_opt ../../s-4.9/gcc/cp/parser.c:10610 0x6304f0 cp_parser_namespace_body ../../s-4.9/gcc/cp/parser.c:15530 0x6304f0 cp_parser_namespace_definition ../../s-4.9/gcc/cp/parser.c:15511 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <<http://gcc.gnu.org/bugs.html>> for instructions. Version: Using built-in specs. COLLECT_GCC=/home/craig/new-gcc/i-4.9/bin/g++ COLLECT_LTO_WRAPPER=/home/craig/new-gcc/i-4.9/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../s-4.9/configure --prefix=/home/craig/new-gcc/i-4.9 Thread model: posix gcc version 4.9.0 20130718 (experimental) (GCC)

Paolo Carlini 2013-07-22 10:30:30 UTC

I can't reproduce this (with or without the std::) Looks like the error message doesn't match the code (line

8 ?!?)

Craig Schroeder 2013-07-22 17:34:47 UTC

Unfortunately that is because I tried cleaning up the test case some more after reducing it down. How about this: namespace std { template <class _E> class initializer_list {}; template <int N> struct D {D(std::initializer_list<int>) {}}; D<0> d{1, 2, 3}; }

Paolo Carlini 2013-07-22 17:39:42 UTC

Ok, thanks.

Paolo Carlini 2013-07-30 10:23:28 UTC

Mine.

Paolo Carlini 2013-07-30 11:14:35 UTC

Not now, sorry. The issue is a bit tricky, not a straightforward error recovery: the name initializer_list triggers magic, necessary to fully implement the C++11 semantics. Thus the issue boils down to treating it as any other name in C++98.

Paolo Carlini 2013-07-30 12:31:50 UTC

Ok, I think I have a way to fix this.

Paolo Carlini 2013-07-30 16:49:29 UTC

Fixed.