-Werror=c++-compat odd behavior
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Nov 26 10:46:00 GMT 2018
On Sun, 25 Nov 2018 at 13:08, <tdwrk@barachs.net> wrote:
>
> This version of gcc:
>
>
>
> $ gcc --version
>
> gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
>
>
>
> Plus this three-liner:
>
>
>
> #define badname im-not-happy
>
> #define initializer(a) #a
>
>
>
> char *only_a_string = initializer(badname);
>
>
>
> Produces:
>
>
>
> $ gcc -c -Werror=c++-compat /tmp/foo.c
>
> /tmp/foo.c:1:20: error: identifier "not" is a special operator name in C++
> [-Werror=c++-compat]
>
> #define badname im-not-happy
>
> ^
>
> cc1: some warnings being treated as errors
>
>
>
> This seems pretty odd... Can someone explain what's going on?
What aprt exactly are you asking about?
The preprocessor sees im-not-happy as five preprocessor tokens, "im"
"-" "not" "-" "happy".
"not" is an operator in C++ (effectively, it's a keyword). The
-Wc++-compat diagnostic is implemented in the preprocessor, which sees
the token "not" and so issues a diagnostic. You asked for that
diagnostic to be an error, so that's what you get.
More information about the Gcc-help
mailing list