]> granicus.if.org Git - clang/commitdiff
Check "late parsed" friend functions for redefinition
authorAlp Toker <alp@nuanti.com>
Fri, 18 Oct 2013 05:54:24 +0000 (05:54 +0000)
committerAlp Toker <alp@nuanti.com>
Fri, 18 Oct 2013 05:54:24 +0000 (05:54 +0000)
r177003 applied the late parsed template technique to friend functions
but omitted the corresponding check for redefinitions.

This patch adds the same check already in use for templates to the
new code path in order to diagnose and reject invalid redefinitions
that were being silently accepted.

Fixes PR17324.

Reviewed by Richard Smith.

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

lib/Parse/ParseCXXInlineMethods.cpp
test/Parser/cxx-friend.cpp

index 8d82d03d8309289d2885dd7ed6709eb285fe8d9a..6bab7988cf0bf92e5c17dfaf96f5da92231c781f 100644 (file)
@@ -176,7 +176,9 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
     // If you remove this, you can remove the code that clears the flag
     // after parsing the member.
     if (D.getDeclSpec().isFriendSpecified()) {
-      getFunctionDecl(FnD)->setLateTemplateParsed(true);
+      FunctionDecl *FD = getFunctionDecl(FnD);
+      Actions.CheckForFunctionRedefinition(FD);
+      FD->setLateTemplateParsed(true);
     }
   } else {
     // If semantic analysis could not build a function declaration,
index a13e7babc534fb911437c425edfc2196c31fb9d6..a3b89cc688bb486e0c2f38560d4d8541da2698aa 100644 (file)
@@ -30,6 +30,10 @@ class B {
   void f(A *a) { a->f(); }
 };
 
+void bar() {} // expected-note {{previous definition is here}}
+class E {
+  friend void bar() {} // expected-error {{redefinition of 'bar'}}
+};