Why does gcc compile this code for the GNU C++ , but not compile for GNU C++11 ?
#include <iostream> int main() { char *s = "string"; std::cout << s[[]{ return 1; }()]; } Because it is forbidden by the C ++ 14 standard (the newer version of the draft is available by reference)
[dcl.attr.grammar] p6 Two consecutive left square bracket tokens. The note is not allowed, it’s not a problem. - end note]
There is even an example:
y[[] { return 2; }()] = 2; // error even though attributes are not allowed // in this context. Well, the first line is not very good either, it should be like this:
const char *s = "string"; GNU C++ why does it compile? - IGORb[[noreturn]] , it says that the function never executes return : it can help the compiler with optimization, the deprecated attribute, to mark outdated functions and so on. At the approach of the attributes to mark variables that are not used consciously and fallthrough for case'ov select. So far this is all just a try of a pen and far from what is in C #, where attributes help a lot of interesting things to do. - ixSciSource: https://ru.stackoverflow.com/questions/584482/
All Articles
expected primary expression before ')' token- IGORbg++have settings? Command line keys - I know, I don’t remember the settings. - PinkTux