]> granicus.if.org Git - clang/commitdiff
fix PR3764 - A redefinition of a pre-processor macro fails
authorChris Lattner <sabre@nondot.org>
Mon, 9 Mar 2009 20:33:32 +0000 (20:33 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 9 Mar 2009 20:33:32 +0000 (20:33 +0000)
Redefinition checking should ignore the leading whitespace and
start of line flags on the first token of an expansion.

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

lib/Lex/MacroInfo.cpp
test/Preprocessor/macro_misc.c

index de19ff502a6a2577d876b23952f55dfbed6e270a..df89450f5a5557b32ee9cf3480e238c8915ee479 100644 (file)
@@ -49,9 +49,14 @@ bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const {
   for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
     const Token &A = ReplacementTokens[i];
     const Token &B = Other.ReplacementTokens[i];
-    if (A.getKind() != B.getKind() || 
-        A.isAtStartOfLine() != B.isAtStartOfLine() ||
-        A.hasLeadingSpace() != B.hasLeadingSpace())
+    if (A.getKind() != B.getKind())
+      return false;
+    
+    // If this isn't the first first token, check that the whitespace and
+    // start-of-line characteristics match.
+    if (i != 0 &&
+        (A.isAtStartOfLine() != B.isAtStartOfLine() ||
+         A.hasLeadingSpace() != B.hasLeadingSpace()))
       return false;
     
     // If this is an identifier, it is easy.
index 66e9e3fcf3eedba78e994e0cb68d24b70e3f7b48..147e827df367d28b0fdf646543e6b89e3872503c 100644 (file)
@@ -4,3 +4,20 @@
 #ifdef defined
 #endif
 
+
+
+// PR3764
+
+// This should not produce a redefinition warning.
+#define FUNC_LIKE(a) (a)
+#define FUNC_LIKE(a)(a)
+
+// This either.
+#define FUNC_LIKE2(a)\
+(a)
+#define FUNC_LIKE2(a) (a)
+
+// This should.
+#define FUNC_LIKE3(a) ( a)  // expected-note {{previous definition is here}}
+#define FUNC_LIKE3(a) (a) // expected-warning {{'FUNC_LIKE3' macro redefined}}
+