https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81129
Bug ID: 81129
Summary: GCC successfully compiles expression into nothing
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
The following code successfully compiles by GCC with -std=c++11 and -std=c++03:
void print(bool) { throw 1; }
int main() {
void(*)(bool){&print}(false);
}
The bad thing is that people expect the code to be a construction of a function
pointer, initialization of it to the address of `print` function and call of
that function. That's not what happens. The whole expression is removed from
the resulting assembly.
Clang fails to compile the code:
main.cpp:4:11: error: expected expression
void(*)(bool){&print}(false);
^
main.cpp:4:17: error: expected '(' for function-style cast or type construction
void(*)(bool){&print}(false);
~~~~^
Please, either make the expression work as expected, or issue a warning, or
fail to compile.