https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117902

            Bug ID: 117902
           Summary: -Wc++-compat can trigger a false-positive about tokens
                    not yet expanded from macro
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: k.ponikwicki17 at gmail dot com
  Target Milestone: ---

-Wc++-compat triggers a false warning when the C95 Alternative Operators
(not, end, and_eq, ...) are used inside of macro body as tokens,
WITHOUT expanding them to actual identifiers.
Said warning is NOT expected to be issued in this case.

References:
https://godbolt.org/z/n6nf1WGnv
https://en.cppreference.com/w/c/language/operator_alternative
https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Warning-Options.html#index-Wc_002b_002b-compat
https://stackoverflow.com/questions/79189642/is-warning-yielded-by-wc-compat-about-identifiers-not-yet-expanded-by-macro-a/79190169

--------------------------------------------------------------

$ cat main.c
#define X_KEYWORDS  \
        X(bool)     \
        X(not)      \
        X(and)      \
        X(or)       \
        X(xor)      \
        X(nullptr)  \
        X(true)     \
        X(false)

int main(void)
{ return 0; }


$ gcc -Wc++-compat main.c
main.c:3:11: warning: identifier "not" is a special operator name in C++
[-Wc++-compat]
    3 |         X(not)      \
      |           ^
main.c:4:11: warning: identifier "and" is a special operator name in C++
[-Wc++-compat]
    4 |         X(and)      \
      |           ^
main.c:5:11: warning: identifier "or" is a special operator name in C++
[-Wc++-compat]
    5 |         X(or)       \
      |           ^
main.c:6:11: warning: identifier "xor" is a special operator name in C++
[-Wc++-compat]
    6 |         X(xor)      \
      |           ^

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/sha
re/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --e
nable-__cxa_atexit --enable-cet=auto --enable-checking=release
--enable-clocale=gnu --enable-default-pie --enable-default-ssp
--enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-
backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto
--enable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-w
error
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240910 (GCC) 

$ uname -sr
Linux 6.12.1-arch1-1

Reply via email to