Why does the following code compile without warnings. Notice that blablabla() is not defined anywhhere.
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());
}
This questions is not a duplicate of the most vexing parse ambiguity, since related examples declare functions with a parameter.
Ahhhh I'm dumb.
It's not treated as a call. The compiler just sees it as a declaration...
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 statement std::string(blablabla()) declares blablabla to be a function returning an std::string, the same as
std::string blablabla();
would do. A local function declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With