#2088 Trigraphs don't work

closed-fixed
Borut Ražem
5
2013-05-25
2012-09-28
No

Compiling this function

void testBug(void)
??<
%>

gives

sdcc -trigraphs test.c
at 1: warning 117: unknown compiler option '-trigraphs' ignored
test.c:2:1: warning: trigraph ??< ignored, use -trigraphs to enable
test.c:2: syntax error: token -> '?' ; column 1

in sdcc 3.2.1 #8116.

Philipp

Discussion

  • Borut Ražem
    Borut Ražem
    2012-12-16

    Fixed in svn revision #8246:
    sdcpp replaces the trigraph sequences by their single-character equivalents if the -trigraphs command line option is defined when called directly or the --trigraphs command line option is defined when called from sdcc.

    Borut

     
  • Borut Ražem
    Borut Ražem
    2012-12-16

    • assigned_to: nobody --> borutr
    • milestone: --> fixed
    • labels: --> C-Front End
    • status: open --> closed-fixed
     
  • Should trigraphs be enabled by default? It would get sdcc closer to standard compliance by default, which seems like a good thing to me. Of course it is unlikely that sdcc will be used to compile code that contains trigraphs. On the other hand it is even more unlikely that sdcc will be used to compile code that contains trigraph sequences that were not meant to be trigraphs.

    Philipp

     
    • status: closed-fixed --> open-fixed
     
  • Borut Ražem
    Borut Ražem
    2012-12-17

    • status: open-fixed --> pending-fixed
     
  • Borut Ražem
    Borut Ražem
    2012-12-17

    Problem is that trigraphs can be also included in constant strings, for example "??<" will be SILENTLY replaced by "{" if trigraphs are enabled. This is probably not what the programmer intended, which introduces higher risk. If somebody is intentionally using trigraphs, he will get the preprocessor warning that he should use the -trigraph option to enable the conversion and the compiler will refuse to compile the code.

    So IMHO it is better to have the trigraph conversion disabled by default. IMO there is higher probability that somebody will unintentionally use the trigraph sequence in the constant string which should not be converted then intentionally use the trigraphs.

    Current behavior is also same as in gcc (if this means anything ;-)

    Borut

     
    • status: pending-fixed --> open-fixed
     
  • Current behaviour is the same as gcc with default options (which is a compiler for some GNU dialect of the C language). When using e.g. gcc --std=c99 trigraphs are handled as the standard requires.
    Also, with sdcc, I get warnings for trigraphs:
    warning: trigraph ??< converted to {
    so anyone using trigraph sequences without meaning to use a trigraph will be alerted to the problem. They will not be replaced silently.

    Philipp

    P.S.: Trigraphs are not an important feature, and the following argument seems like an exxageration even to its author: Having trigraphs disabled by default is like replacing = by == in if conditions by default: Both trigraphs and = might have been written with an intention that differs from what the standard says they mean.

     
  • Borut Ražem
    Borut Ražem
    2012-12-17

    > Also, with sdcc, I get warnings for trigraphs:
    > warning: trigraph ??< converted to {
    > so anyone using trigraph sequences without meaning to use a trigraph will
    > be alerted to the problem. They will not be replaced silently.

    This is because sdcc passes the -Wall option to sdcpp. If you invoke sdcpp directly without -Wall or -Wtrigraphs the warning will not be shown.

    OK, I'll modify the sdcpp so that trigraphs processing will be always enabled as required by the standard.
    What about the warning? Should it be enabled by default and disabled by -Wno-trigraphs or disabled by default and enabled by -Wtrigraphs?

    I don't intend to implement -W(no-)trigraphs in sdcc. The option can be passed to sdcpp by --Wp,-W(no-)trigraphs.

    > P.S.: Trigraphs are not an important feature...

    Trigraphs become important feature when the program behaves differently then intended by the author.

    I'm sure that more then 99% of c programmers will expect that printf("??<"); will print ??< and not {. Maybe some of them will say "Oh, I forgot about trigraphs" when they'll see the result, all other will submit a bug report to the compiler developers after one day or so of banging their heads against the wall.

    Borut

     
  • Borut Ražem
    Borut Ražem
    2012-12-19

    • status: open-fixed --> pending-fixed
     
  • Borut Ražem
    Borut Ražem
    2012-12-19

    2nd try in svn revision #8252:
    - trigraphs are now enabled by default in sdcpp as required by the standard. They can still be disabled by -no-trigraphs from sdcpp or by -Wp,-no-trigraphs from sdcc.
    - trigraphs warnings are enabled by default in sdcpp. They can be disabled by -Wno-trigraphs from sdcpp or by -Wp,-Wno-trigraphs from sdcc.

    Maybe we should also disable warnings in case of -std=cXX to be more standard compliant? Opinions (Philipp)?

    Borut

     
  • Thanks. Well, formally, the standard sometimes requires issuing a warning, but it never requires not issuing a warning*. Personally, I feel when using --std, we should never issue a warning for compliant code that does not invoce deprectated, undefined or implementation-defined behaviour (unless requested by some other option). However, I don't feel strongly about it wrt. to trigraphs.

    Philipp

    * Technically, a compiler that just issues a warning for every program it compiles and generates code for a program always returning 0 would be compliant.

     
    • status: pending-fixed --> open-fixed
     
  • Borut Ražem
    Borut Ražem
    2012-12-19

    OK, I'll leave the trigraphs warning enabled since I think this is more secure (see the arguments in my previous comments).

    Borut

     
  • Borut Ražem
    Borut Ražem
    2012-12-19

    • status: open-fixed --> pending-fixed
     
  • Borut Ražem
    Borut Ražem
    2012-12-19

    • status: pending-fixed --> closed-fixed