From 4b44baf46b47a7e6addbaed0b4c7c99a5e0647fb Mon Sep 17 00:00:00 2001 From: Benjamin Kramer <benny.kra@googlemail.com> Date: Mon, 17 Apr 2017 20:57:40 +0000 Subject: [PATCH] Revert "Address http://bugs.llvm.org/pr30994 so that a non-friend can properly replace a friend, and a visible friend can properly replace an invisible friend but not vice verse, and definitions are not replaced. This fixes the two FIXME in SemaTemplate/friend-template.cpp." This reverts commit r300443. Breaks compiling libc++ with modules in some configurations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300497 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclBase.h | 2 -- lib/AST/Decl.cpp | 4 ---- lib/AST/DeclBase.cpp | 15 --------------- test/SemaTemplate/friend-template.cpp | 26 +++++++++++++------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 5ca1f1ec6ed..c88cb6a8fd1 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -417,8 +417,6 @@ public: return const_cast<Decl*>(this)->getTranslationUnitDecl(); } - bool isThisDeclarationADefinition() const; - bool isInAnonymousNamespace() const; bool isInStdNamespace() const; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 6a288cdb21f..2b22e5bb50a 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1536,10 +1536,6 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const { if (isa<ObjCMethodDecl>(this)) return false; - if (getFriendObjectKind() > OldD->getFriendObjectKind() && - !isThisDeclarationADefinition()) - return false; - // For parameters, pick the newer one. This is either an error or (in // Objective-C) permitted as an extension. if (isa<ParmVarDecl>(this)) diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index ae7444579b0..cda70c5edcd 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -861,21 +861,6 @@ const FunctionType *Decl::getFunctionType(bool BlocksToo) const { return Ty->getAs<FunctionType>(); } -bool Decl::isThisDeclarationADefinition() const { - if (auto *TD = dyn_cast<TagDecl>(this)) - return TD->isThisDeclarationADefinition(); - if (auto *FD = dyn_cast<FunctionDecl>(this)) - return FD->isThisDeclarationADefinition(); - if (auto *VD = dyn_cast<VarDecl>(this)) - return VD->isThisDeclarationADefinition(); - if (auto *CTD = dyn_cast<ClassTemplateDecl>(this)) - return CTD->isThisDeclarationADefinition(); - if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this)) - return FTD->isThisDeclarationADefinition(); - if (auto *VTD = dyn_cast<VarTemplateDecl>(this)) - return VTD->isThisDeclarationADefinition(); - return false; -} /// Starting at a given context (a Decl or DeclContext), look for a /// code context that is not a closure (a lambda, block, etc.). diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 1ed751b4f36..e9b2b9b8e64 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // PR5057 namespace test0 { namespace std { @@ -68,12 +68,17 @@ namespace test3 { Foo<int> foo; template<typename T, T Value> struct X2a; - template<typename T, int Size> struct X2b; // expected-note {{previous non-type template parameter with type 'int' is here}} + + template<typename T, int Size> struct X2b; template<typename T> class X3 { template<typename U, U Value> friend struct X2a; - template<typename U, T Value> friend struct X2b; // expected-error {{template non-type parameter has a different type 'long' in template redeclaration}} + + // FIXME: the redeclaration note ends up here because redeclaration + // lookup ends up finding the friend target from X3<int>. + template<typename U, T Value> friend struct X2b; // expected-error {{template non-type parameter has a different type 'long' in template redeclaration}} \ + // expected-note {{previous non-type template parameter with type 'int' is here}} }; X3<int> x3i; // okay @@ -292,11 +297,14 @@ namespace PR12585 { int n = C::D<void*>().f(); struct F { - template<int> struct G; // expected-note {{previous}} + template<int> struct G; }; template<typename T> struct H { + // FIXME: As with cases above, the note here is on an unhelpful declaration, + // and should point to the declaration of G within F. template<T> friend struct F::G; // \ - // expected-error {{different type 'char' in template redeclaration}} + // expected-error {{different type 'char' in template redeclaration}} \ + // expected-note {{previous}} }; H<int> h1; // ok H<char> h2; // expected-note {{instantiation}} @@ -321,11 +329,3 @@ namespace rdar12350696 { foo(b); // expected-note {{in instantiation}} } } -namespace PR30994 { - void f(); - struct A { - [[deprecated]] friend void f() {} // \ - expected-note {{has been explicitly marked deprecated here}} - }; - void g() { f(); } // expected-warning {{is deprecated}} -} -- GitLab