Why "std :: string (blablabla ()); compile without errors?

Why the following code compiles without warning. Note that blablabla () is not defined by any means.

I tested it in gcc 5.1.0 and clang-3.7.0 (with and without the -std = C ++ 11 flag).

 #include <string> int main() { std::string(blablabla()); } 

These questions are not a duplicate of the most unpleasant parsing uncertainty, since related examples declare functions with a parameter.

+7
c ++ c ++ 11 compilation compiler-errors
source share
1 answer

Yeah, I'm dumb.

It is not seen as a challenge. The compiler just sees this as an announcement ...

Try, for comparison:

 int main() { int(blablabla); } 

This gives:

 test.c++: In function 'int main()': test.c++:6:9: warning: unused variable 'blablabla' [-Wunused-variable] int(blablabla); ^ 

More precisely, your std::string(blablabla()) blablabla declares blablabla function returning std::string , just like

 std::string blablabla(); 

. Declaring a local function.

+8
source share

All Articles