Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

__VA_OPT__ is only supported by Clang's preprocessor in C++2a mode but GCC seems to support it in all language modes #39636

Open Quuxplusone opened 5 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR40665
Status NEW
Importance P enhancement
Reported by Dan Liew (dan@su-root.co.uk)
Reported on 2019-02-08 08:56:57 -0800
Last modified on 2019-02-08 12:41:02 -0800
Version trunk
Hardware PC All
CC dan@su-root.co.uk, faisalv@yahoo.com, hstong@ca.ibm.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments varargs.cxx (155 bytes, text/plain)
Blocks
Blocked by
See also

The attached program can be compiled by GCC 8.2.1 in various language modes

gcc -x c -std=gnu89 varargs.c
gcc -x c -std=gnu99 varargs.c
gcc -x c -std=gnu11 varargs.c
gcc -x c -std=gnu89 varargs.c
gcc -x c -std=gnu99 varargs.c
gcc -x c -std=gnu11 varargs.c
g++ -x c++ -std=c++98 varargs.c
g++ -x c++ -std=c++11 varargs.c
g++ -x c++ -std=c++14 varargs.c
g++ -x c++ -std=c++17 varargs.c
g++ -x c++ -std=c++2a varargs.c
g++ -x c++ -std=gnu++98 varargs.c
g++ -x c++ -std=gnu++11 varargs.c
g++ -x c++ -std=gnu++14 varargs.c
g++ -x c++ -std=gnu++17 varargs.c
g++ -x c++ -std=gnu++2a varargs.c

but Clang fails to compile it because the __VA_OPT__() macro does not get expanded for all of the above language variants except for c++2a and gnu++2a.

I believe __VA_OPT_() is a C++2a feature so Clang is probably more correct here.

However according to https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html __VA_OPT_() is supposed to be available for GNU C and GNU C++ too so we probably ought to enable it when we are compiling for the GNU language variants -std=gnu*.

The fact that GCC allows __VA_OPT__() in non-GNU language variants that isn't c++2a seems like a bug but I am not currently in a position to report it.

Quuxplusone commented 5 years ago

Since VA_OPT is a reserved identifier, enabling the use of VA_OPT in all language modes should be fine. A gratuitous difference from GCC is not desirable.

Quuxplusone commented 5 years ago

Perhaps, but this might just be a mistake in GCC's implementation that gets fixed later. It would be better if we talked to the GCC folks and come to an agreement what the correct behaviour is and then implement the same (or at least very similar) in both GCC and Clang.

Quuxplusone commented 5 years ago

Attached varargs.cxx (155 bytes, text/plain): example program

Quuxplusone commented 5 years ago

For convenience. Here's the program on Godbolt. https://godbolt.org/z/USde4M

Quuxplusone commented 5 years ago

We generally accept conforming extensions such as this in prior language modes. Unless there's a reason not to do so, we should accept __VA_OPT__ in all language modes (with an Extension or ExtWarn diagnostic) irrespective of what GCC does.