]> granicus.if.org Git - clang/commitdiff
Don't give # and ## special treatment when in -traditional-cpp mode. Patch by
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 9 Jul 2013 01:00:29 +0000 (01:00 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 9 Jul 2013 01:00:29 +0000 (01:00 +0000)
Austin Seipp!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185896 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/traditional-cpp.c

index 026a7e72288bca7e687e6e6f100fd756042e75a6..cb56615ddcc4b2e361ece86e3bc27226c91b28f5 100644 (file)
@@ -1905,6 +1905,18 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
         continue;
       }
 
+      // If we're in -traditional mode, then we should ignore stringification
+      // and token pasting. Mark the tokens as unknown so as not to confuse
+      // things.
+      if (getLangOpts().TraditionalCPP) {
+        Tok.setKind(tok::unknown);
+        MI->AddTokenToBody(Tok);
+
+        // Get the next token of the macro.
+        LexUnexpandedToken(Tok);
+        continue;
+      }
+
       if (Tok.is(tok::hashhash)) {
         
         // If we see token pasting, check if it looks like the gcc comma
index 4c4633e039209b8ac91d4f0430cccf5aa88038db..b8bb99d93cbb96216ccf97827ccbcd71f2a4dd9c 100644 (file)
@@ -88,3 +88,20 @@ a b c in skipped block
 Preserve URLs: http://clang.llvm.org
 /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
  */
+
+/* The following tests ensure we ignore # and ## in macro bodies */
+
+#define FOO_NO_STRINGIFY(a) test(# a)
+FOO_NO_STRINGIFY(foobar)
+/* CHECK: {{^}}test(# foobar){{$}}
+ */
+
+#define FOO_NO_PASTE(a, b) test(b##a)
+FOO_NO_PASTE(foo,bar)
+/* CHECK {{^}}test(bar##foo){{$}}
+ */
+
+#define BAR_NO_STRINGIFY(a) test(#a)
+BAR_NO_STRINGIFY(foobar)
+/* CHECK: {{^}}test(#foobar){{$}}
+ */