Re: -Werror=c++-compat odd behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 25 Nov 2018 at 13:08, <tdwrk@xxxxxxxxxxx> 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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux