Check "late parsed" friend functions for redefinition
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
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp
index 8d82d03..6bab798 100644
--- a/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/lib/Parse/ParseCXXInlineMethods.cpp
@@ -176,7 +176,9 @@
// 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,
diff --git a/test/Parser/cxx-friend.cpp b/test/Parser/cxx-friend.cpp
index a13e7ba..a3b89cc 100644
--- a/test/Parser/cxx-friend.cpp
+++ b/test/Parser/cxx-friend.cpp
@@ -30,6 +30,10 @@
void f(A *a) { a->f(); }
};
+void bar() {} // expected-note {{previous definition is here}}
+class E {
+ friend void bar() {} // expected-error {{redefinition of 'bar'}}
+};