Why is this invalid code code successfully compiled in g ++ 6.0?

Consider this strange program:

int main() { int(*){} Is it C++14 or any other language? } 

(see live demo here and here .)

Even if there is no // comment , the code compiles without errors and warnings, even when I use the -pedantic-errors options in g ++ 6.0. This seems like a compiler error. Is this really a compiler error?

+83
c ++ g ++
Nov 09 '15 at 17:12
source share
2 answers

It looks like a bug / function / problem with g ++ in all versions that I can check for. Launch

 int main() { int(*){} Is it C++14 or any other language? } 

In godbolt.org, for all versions of g ++ without compilation flags, the following output from the assembly is given.

 main: pushq %rbp movq %rsp, %rbp movl $0, %eax leave ret 

The only diagnosis I get is on godbolt.org , and that’s

 !!warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x 

Clang, ICC, and MSVS cannot compile this.

EDIT:

From zwol comments filed an error with gcc on this. An error report can be found here .

+43
Nov 09 '15 at 17:24
source share

I ran the command on my Fedora VM using g++ version 5.1.1 and found the following:

 [user:~] 1 $ g++ -fdump-tree-original-raw tmp.cpp tmp.cpp: In function 'int main()': tmp.cpp:3:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 int(*){} Is it C++14 or any other language? ^ 

However, it still managed to compile ... So I dropped the AST and got the following:

 $ cat tmp.cpp.003t.original ;; Function int main() (null) ;; enabled by -tree-original @1 return_expr type: @2 expr: @3 @2 void_type name: @4 algn: 8 @3 init_expr type: @5 op 0: @6 op 1: @7 @4 type_decl name: @8 type: @2 srcp: <built-in>:0 note: artificial @5 integer_type name: @9 size: @10 algn: 32 prec: 32 sign: signed min : @11 max : @12 @6 result_decl type: @5 scpe: @13 srcp: tmp.cpp:1 note: artificial size: @10 algn: 32 @7 integer_cst type: @5 int: 0 @8 identifier_node strg: void lngt: 4 @9 type_decl name: @14 type: @5 srcp: <built-in>:0 note: artificial @10 integer_cst type: @15 int: 32 @11 integer_cst type: @5 int: -2147483648 @12 integer_cst type: @5 int: 2147483647 @13 function_decl name: @16 type: @17 scpe: @18 srcp: tmp.cpp:1 lang: C link: extern @14 identifier_node strg: int lngt: 3 @15 integer_type name: @19 size: @20 algn: 128 prec: 128 sign: unsigned min : @21 max : @22 @16 identifier_node strg: main lngt: 4 @17 function_type size: @23 algn: 8 retn: @5 prms: @24 @18 translation_unit_decl @19 identifier_node strg: bitsizetype lngt: 11 @20 integer_cst type: @15 int: 128 @21 integer_cst type: @15 int: 0 @22 integer_cst type: @15 int: -1 @23 integer_cst type: @15 int: 8 @24 tree_list valu: @2 

Which is too large to fit in the comment, but should be useful in determining what is happening. I am still experiencing this, but I just post this information for others to build from.

What is visualized as follows enter image description here .

+15
Nov 09 '15 at 10:50
source share



All Articles