Closed Quuxplusone closed 4 years ago
Bugzilla Link | PR43282 |
Status | RESOLVED FIXED |
Importance | P normal |
Reported by | Tom Hender (ToHe_EMA@gmx.de) |
Reported on | 2019-09-11 10:23:01 -0700 |
Last modified on | 2020-02-25 14:28:25 -0800 |
Version | trunk |
Hardware | PC All |
CC | Balazs.CZIRAKI@nng.com, berglerma@gmail.com, epastor@google.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, rnk@google.com |
Fixed by commit(s) | D69626 |
Attachments | |
Blocks | |
Blocked by | |
See also |
I think this has been reported a few times. Issue 42112 looks like the closest,
but there may be others.
We're in a bad situation where clang -fms-compatibility is neither standards
conformant nor MSVC compatible, and users (Boost) in the past have been
frustrated with that, since they don't want to add ifdefs to cope with our
buggy compatibility hacks.
My hope is that MSVC will implement conforming rules, as described here, and
then we will tell users to turn that on and everything will be standard:
https://devblogs.microsoft.com/cppblog/msvc-preprocessor-progress-towards-conformance/
_Bug 43584 has been marked as a duplicate of this bug._
Working with an instrumented version of pp-trace, I've managed to minimize the
repro a bit further:
#define TEST(...) COMBINE(THIRD_ARGUMENT(__VA_ARGS__, "a", "b"))
#define THIRD_ARGUMENT(A, B, C, ...) C
#define COMBINE(...) __VA_ARGS__
static_assert(0, TEST(,));
This should output "a" because TEST() gets a comma inside the __VA_ARGS__...
but with -fms-compatibility, single commas are flagged with Token::IgnoredComma
to keep from being considered as an argument separator, so we instead output
"b".
If we instead use
#define TEST(...) THIRD_ARGUMENT(__VA_ARGS__, "a", "b")
without the COMBINE(), we still output "b" successfully replicate the non-
compliance of the MSVC preprocessor. However, MSVC behaves correctly when the
intervening COMBINE() is in place - and we don't!
To fix this, we need to clear the IgnoredComma flag at the right point when
expanding with an intervening macro. I don't really understand
PPMacroExpansion.cpp yet, so I haven't found the right point to do this. Anyone
else have an idea?
I believe https://reviews.llvm.org/D69626 will fix this.
_Bug 45005 has been marked as a duplicate of this bug._