[PATCH] D26148: Add missing cases to FunctionDecl::isThisDeclarationADefinition

Serge Pavlov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 07:00:07 PDT 2016


sepavloff created this revision.
sepavloff added a subscriber: cfe-commits.

This change adds to the method isThisDeclarationADefinition additional
conditions under which a function declaration becomes a definition.
These includes the case of a declaration that does not have a function
body because the latter is not instantiated yet.


https://reviews.llvm.org/D26148

Files:
  include/clang/AST/Decl.h
  test/SemaCXX/cxx0x-cursory-default-delete.cpp


Index: test/SemaCXX/cxx0x-cursory-default-delete.cpp
===================================================================
--- test/SemaCXX/cxx0x-cursory-default-delete.cpp
+++ test/SemaCXX/cxx0x-cursory-default-delete.cpp
@@ -136,13 +136,13 @@
 };
 
 struct DefaultDelete {
-  DefaultDelete() = default; // expected-note {{previous declaration is here}}
+  DefaultDelete() = default; // expected-note {{previous definition is here}}
   DefaultDelete() = delete; // expected-error {{constructor cannot be redeclared}}
 
-  ~DefaultDelete() = default; // expected-note {{previous declaration is here}}
+  ~DefaultDelete() = default; // expected-note {{previous definition is here}}
   ~DefaultDelete() = delete; // expected-error {{destructor cannot be redeclared}}
 
-  DefaultDelete &operator=(const DefaultDelete &) = default; // expected-note {{previous declaration is here}}
+  DefaultDelete &operator=(const DefaultDelete &) = default; // expected-note {{previous definition is here}}
   DefaultDelete &operator=(const DefaultDelete &) = delete; // expected-error {{class member cannot be redeclared}}
 };
 
Index: include/clang/AST/Decl.h
===================================================================
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1831,14 +1831,26 @@
     return getBody(Definition);
   }
 
-  /// isThisDeclarationADefinition - Returns whether this specific
-  /// declaration of the function is also a definition. This does not
-  /// determine whether the function has been defined (e.g., in a
-  /// previous definition); for that information, use isDefined. Note
-  /// that this returns false for a defaulted function unless that function
-  /// has been implicitly defined (possibly as deleted).
+  /// Returns whether this specific declaration of the function is also
+  /// a definition.
+  ///
+  /// The method checks for definiteness of the declaration in the sense, used
+  /// in redefinition checks. A defined function usually cannot have more than
+  /// one definition. At the same time it may have its body absent, for instance,
+  /// because it does not exist at all as in deleted functions, or is not
+  /// instantiated yet as in templated entities. Corresponding declarations are
+  /// also reported as definitions.
+  ///
+  /// This does not determine whether the function has been defined (e.g., in a
+  /// previous definition); for that information, use isDefined.
+  ///
   bool isThisDeclarationADefinition() const {
-    return IsDeleted || Body || IsLateTemplateParsed;
+    if (IsDeleted || IsDefaulted || Body || IsLateTemplateParsed ||
+        hasDefiningAttr())
+      return true;
+    if (FunctionDecl *Original = getInstantiatedFromMemberFunction())
+      return Original->isThisDeclarationADefinition();
+    return false;
   }
 
   /// doesThisDeclarationHaveABody - Returns whether this specific


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26148.76395.patch
Type: text/x-patch
Size: 2883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161031/d3661d38/attachment.bin>


More information about the cfe-commits mailing list