Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a switch to disable trigraphs with clang?

I've got some (legacy) code that I'm building with clang for the first time. The code is something like:

sprintf(buf, "%s <%s ????>", p1, p2);

Clang gives the following warning (error with -Werror):

test.c:6:33: error: trigraph converted to '}' character [-Werror,-Wtrigraphs]
    sprintf(buf, "%s <%s ????>", p1, p2);
                           ^

Clearly the ??> is not intended as a trigraph, so I want to disable trigraphs entirely (the source does not intentionally use them anywhere).

I have tried -no-trigraphs but that's not really an option:

clang: warning: argument unused during compilation: '-no-trigraphs'

I can turn off the trigraphs warning with -Wno-trigraphs but I don't want the trigraph conversion to actually take place at all.

NOTE: Trigraphs were enabled as an unintended side effect of using -std=c89.

like image 807
Greg Hewgill Avatar asked Feb 21 '12 23:02

Greg Hewgill


People also ask

How do I enable Trigraphs?

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > Command Line property page. Modify the Additional Options property to include /Zc:trigraphs or /Zc:trigraphs- and then choose OK.

Does clang use GCC?

Clang is compatible with GCC. Its command-line interface shares many of GCC's flags and options. Clang implements many GNU language extensions and compiler intrinsics, some of which are purely for compatibility.


2 Answers

Try using gnu* mode - "Trigraphs default to being off in gnu* modes; they can be enabled by the -trigraphs option." (see http://clang.llvm.org/docs/UsersManual.html#c_modes for other differences and command line switch)

like image 183
yachoor Avatar answered Oct 13 '22 00:10

yachoor


I couldn't see an obvious way to disable trigraphs (rather than the trigraphs warning). Probably the easiest way to fix this code is to change it to:

sprintf(buf, "%s <%s ????"">", p1, p2);
like image 34
Hugh Avatar answered Oct 13 '22 01:10

Hugh