This question already has an answer here:
- Strange code that compiles with g++ 3 answers
Consider this strange program:
int main()
{
int(*){} Is it C++14 or any other language?
}
(See a live demo here & here.)
Even though the comment //
is missing, the code compiles fine without any errors & warnings even when I use -pedantic-errors
options in g++ 6.0. This seems like a compiler bug to me. Is it really a bug in the compiler?
I've run the command on my Fedora VM with
g++
version5.1.1
and found the following:However that still managed to compile... So I've dumped the AST and got this:
Which is too big to fit inside a comment but should be useful in determining what is going on. I'm still going through this but I'm just posting this information for others to build from.
Which is visualized like this .
This looks to be an bug/feature/issue with g++ in all of the versions I can test it on. Running
On godbolt.org for all versions of g++ with no compilation flags give the following assembly ouput.
The only diagnosis I get is on godbolt.org and that is
Clang, ICC and MSVS all fail to compile this.
EDIT:
From the comments zwol filed a bug with gcc on this. The bug report can be found here.