]> granicus.if.org Git - clang/commitdiff
Reverted 305379 (Function with unparsed body is a definition)
authorSerge Pavlov <sepavloff@gmail.com>
Wed, 14 Jun 2017 10:57:56 +0000 (10:57 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Wed, 14 Jun 2017 10:57:56 +0000 (10:57 +0000)
It broke clang-x86_64-linux-selfhost-modules-2 and some other buildbots.

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

include/clang/AST/Decl.h
lib/Sema/SemaCUDA.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaCXX/friend2.cpp

index 94cb66fd2bfa8ac0645051f73432a04f0b4be6ab..9d49bac26a86899f666d3b7533d4380618e5135d 100644 (file)
@@ -1872,7 +1872,7 @@ public:
   ///
   bool isThisDeclarationADefinition() const {
     return IsDeleted || IsDefaulted || Body || IsLateTemplateParsed ||
-      WillHaveBody || hasDefiningAttr();
+      hasDefiningAttr();
   }
 
   /// doesThisDeclarationHaveABody - Returns whether this specific
index cac5f682275eddce2617dd784344d2e21bcfb76f..b938ac387c4dae0e3b1a85a7171ec0973bc2fe7e 100644 (file)
@@ -629,6 +629,12 @@ static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) {
   // emitted, because (say) the definition could include "inline".
   FunctionDecl *Def = FD->getDefinition();
 
+  // We may currently be parsing the body of FD, in which case
+  // FD->getDefinition() will be null, but we still want to treat FD as though
+  // it's a definition.
+  if (!Def && FD->willHaveBody())
+    Def = FD;
+
   if (Def &&
       !isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(Def)))
     return true;
index 9763eb5611a08ae660f5e0af9b2796d123c91cca..cba220daf774c786119511d8caf75e0b8421da42 100644 (file)
@@ -12218,7 +12218,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
 
   if (FD) {
     FD->setBody(Body);
-    FD->setWillHaveBody(false);
 
     if (getLangOpts().CPlusPlus14) {
       if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() &&
index 0b46e15bb0a3286a872c4b20b0fc70f9a7ff63db..844299bb87cf1a0ab7d302b63b7e667b2236a117 100644 (file)
@@ -13878,9 +13878,6 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) {
     return;
   }
 
-  // Deleted function does not have a body.
-  Fn->setWillHaveBody(false);
-
   if (const FunctionDecl *Prev = Fn->getPreviousDecl()) {
     // Don't consider the implicit declaration we generate for explicit
     // specializations. FIXME: Do not generate these implicit declarations.
index 11c6c519b61f8dbfc812ca70ec9ebc287a08dae6..148ce24293a09deaab196a75b4d01b85d5d54c19 100644 (file)
@@ -1782,12 +1782,6 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
       Previous.clear();
   }
 
-  if (isFriend) {
-    Function->setObjectOfFriendDecl();
-    if (FunctionTemplate)
-      FunctionTemplate->setObjectOfFriendDecl();
-  }
-
   SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,
                                    isExplicitSpecialization);
 
@@ -1798,6 +1792,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
   // If the original function was part of a friend declaration,
   // inherit its namespace state and add it to the owner.
   if (isFriend) {
+    PrincipalDecl->setObjectOfFriendDecl();
     DC->makeDeclVisibleInContext(PrincipalDecl);
 
     bool QueuedInstantiation = false;
index d5087df5d8d2c898256b5f12675f20a0d3542e61..347af0d61b1bcdccad384634d83cf2266298a87d 100644 (file)
@@ -170,15 +170,3 @@ struct Test {
 template class Test<int>;
 
 }
-
-namespace pr14785 {
-template<typename T>
-struct Somewhat {
-  void internal() const { }
-  friend void operator+(int const &, Somewhat<T> const &) {}  // expected-error{{redefinition of 'operator+'}}
-};
-
-void operator+(int const &, Somewhat<char> const &x) {  // expected-note {{previous definition is here}}
-  x.internal();  // expected-note{{in instantiation of template class 'pr14785::Somewhat<char>' requested here}}
-}
-}