llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.82k stars 11.46k forks source link

-Wc++2a-compat erroneously emitted before preprocessing is complete #43053

Open llvmbot opened 4 years ago

llvmbot commented 4 years ago
Bugzilla Link 43708
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

Compile the following with -std=c++17 -Wc++2a-compat -Werror:

define LPAREN (

define EXPAND(...) __VA_ARGS__

define EAT(...)

EAT(requires) // OK, no warning. EXPAND(EAT LPAREN requires)) // Oops, warning.

This file emits no tokens after full preprocessing; however, the compiler still complains about the presence of the requires keyword on the last line. Note that EAT(requires) compiles without warning, which leads me to believe that the warning is looking for C++20 keywords after each macro expansion instead of after full expansion.

wheatman commented 11 months ago

This behavior still happens with post 17 trunk(bfa3bc437809e0496a79a5ff690212e05b053ab3) https://godbolt.org/z/a9cT3vn1q

code

  // compile with -std=c++17 -Wc++2a-compat
  #define LPAREN (
  #define EXPAND(...) __VA_ARGS__
  #define EAT(...)
  EAT(requires) // OK, no warning.
  EXPAND(EAT LPAREN requires)) // Oops, warning.

warning

<source>:6:21: warning: 'requires' is a keyword in C++20 [-Wc++20-compat]
    6 |   EXPAND(EAT LPAREN requires)) // Oops, warning.
      |                     ^
1 warning generated.
Compiler returned: 0
shafik commented 11 months ago

CC @AaronBallman @cor3ntin