Question

After reading up on digraphs and trigraphs I went on and tested a simple program:

#include <stdio.h>

int main()
{
   int a = 0;
   //??/
   ++a;
   printf("%d",a);
   return 0;
}

and by reflex I did

g++ -std=c++11 test.c

and to my surprise no warnings were emitted and 0 was printed so I went on and tried compiling with the C compiler and it did emit a warning due to the trigraph.

My question is why does -std=c++11 automatically pull in -trigraphs and emit no warning by default ? (without using -Wall) Do implementations of certain C++11 features require them? (highly doubt it but worth asking)

Was it helpful?

Solution

Passing -std=c99 has the same effect of enabling the trigraph and disabling the warning.

It must enable the trigraph to be strictly standard-compliant. Disabling the warning is surprising, but note that the warning is about a trigraph being ignored. The warning probably goes away because -std failed to activate separate warnings (-Wtrigraphs) about a trigraph being used.

And that should probably be considered a bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top