From: Alp Toker Date: Fri, 18 Oct 2013 05:54:24 +0000 (+0000) Subject: Check "late parsed" friend functions for redefinition X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=530fa4fc800f2788cfe6d4113677ca631d1e801f;p=clang 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 8d82d03d83..6bab7988cf 100644 --- a/lib/Parse/ParseCXXInlineMethods.cpp +++ b/lib/Parse/ParseCXXInlineMethods.cpp @@ -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, diff --git a/test/Parser/cxx-friend.cpp b/test/Parser/cxx-friend.cpp index a13e7babc5..a3b89cc688 100644 --- a/test/Parser/cxx-friend.cpp +++ b/test/Parser/cxx-friend.cpp @@ -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'}} +};