In gcc , a strange error occurs when I try to compile this code. There is no such thing in clang . What is the problem?

#error This is an ISO C ++ 2011 standard. This support must be enabled with the -std = c ++ 11 or -std = gnu ++ 11 compiler options.

 #include <random> int main() { int x; //Почему тут ошибка??/ x = 0x42; // <-- } 
  • 2
    Comments tried to clean? There with trigraphs, the story is interesting. - αλεχολυτ
  • Neither gcc nor even g++ give me such an error. How do you compile? - andreymal
  • Most likely the author of the question forgot the include list. And there may well be something new. - KoVadim
  • @ älёxölüt really compiles without comments - strange
  • 3
    So <random> is from c ++ 11, therefore it requires :) - αλεχολυτ

1 answer 1

The code uses the header file <random> , which is characteristic of the standard c ++ 11 and higher, therefore the mentioned error is observed. In addition, there are some trigraphs in the code (which, by the way, have already been banned in c ++ 17), maybe this also indirectly gave reason to think that the error is not where it really is.

Regarding the basis on which clang collects code with <random> in -std=c++98 mode, asked a question to enSO Enforcing C ++ 98/03 for clang . In the comments, people express confidence that this is a clang bug.