c++ – I want to disable trigraph in C ++ 11

Question: Question:

The sources are as follows:


#include <stdio.h>

int main()
        return 0;

If you compile this like g++ test.cpp , the execution result is as expected.
But with g++ -std=c++11 test.cpp , (???) becomes (?] .

clang++ -std=c++1z test.cpp works as expected, but
Debian (jessie) g ++ 4.9.2 does not allow you to specify c++1z .
In g ++ 5.4.0 of Ubuntu (16.04), c++1z can be specified and it works as expected.

Is there a way to enable c ++ 11 in g ++ 4.9.2 and disable the trigraph?

Answer: Answer:

Trigraphs are part of the C ++ language specification, and it seems that trigraphs cannot be disabled in GCC's ISO C ++ compliant mode ( -std=c++11 ).

To avoid the trigraph, you need to escape (1) \? Or (2) split the string literal. We also strongly recommend specifying the -Wall option to avoid unintended trigraph conversions.

puts("(??\?)");   // (1)
puts("(??""?)");  // (2)

puts("(???)");  // "(?]"に変換される
// warning: trigraph ??) converted to ] [-Wtrigraphs]


Bonus: In the next standard C ++ 1z (scheduled for C ++ 17), the trigraph will be removed from the specifications . This is why trigraphs are disabled with the new GCC and c ++ 1z compliance specifications for Clang. In the future you won't have to worry about it.

Scroll to Top