0

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)

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
user1233963
  • 1,450
  • 15
  • 41
  • Trigraphs are required by the standard, so requesting `-std=c++11` turns them on. Hardly anyone anywhere needs them, nothing depends on them. – Jonathan Wakely Jan 09 '13 at 23:35
  • stdio.h is no longer the c++ way as far as i know, prefer #include this is the standard c++ way – Stephane Rolland Jan 09 '13 at 23:36
  • 3
    @StephaneRolland, `` is part of C++, it's just deprecated in favour of ``. Exactly the same status in had in C++98. Including `` won't help you use `printf`, which is not deprecated. The "C++ way" is to use the right tool for the job. – Jonathan Wakely Jan 09 '13 at 23:36
  • @JonathanWakely I just repeat what I've been answered here, and for good. – Stephane Rolland Jan 09 '13 at 23:37
  • @JonathanWakely and the right tool to use, isn't it ? – Stephane Rolland Jan 09 '13 at 23:40
  • (i'm proposed to go to chat you're ok ?) – Stephane Rolland Jan 09 '13 at 23:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22487/discussion-between-jonathan-wakely-and-stephane-rolland) – Jonathan Wakely Jan 09 '13 at 23:41
  • @user1233963, sorry, I realised I was using an alias that turned on `-Wall` - you're right no warning by default. Most warnings are not on by default. If you want warnings ask for them. Trigraphs are part of the standard, so warning about them by default would be questionable, I guess. – Jonathan Wakely Jan 09 '13 at 23:43

1 Answers1

3

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.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421