]> granicus.if.org Git - clang/commitdiff
When we see something that looks like a constructor with a return type, only issue...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 6 Jul 2015 01:04:39 +0000 (01:04 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 6 Jul 2015 01:04:39 +0000 (01:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241424 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/CXX/class/class.mem/p2.cpp
test/CXX/drs/dr1xx.cpp
test/Parser/cxx-default-delete.cpp
test/SemaCXX/constructor.cpp

index 6508d6f04bb26486ef7f4ffab84a730cb16bd59c..3c0e83c5a25b6082ff1ce01c17d75105a66686f8 100644 (file)
@@ -4742,15 +4742,16 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D,
     }
   }
 
-  if (DiagnoseClassNameShadow(DC, NameInfo))
+  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
+  QualType R = TInfo->getType();
+
+  if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo))
     // If this is a typedef, we'll end up spewing multiple diagnostics.
-    // Just return early; it's safer.
+    // Just return early; it's safer. If this is a function, let the
+    // "constructor cannot have a return type" diagnostic handle it.
     if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
       return nullptr;
 
-  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
-  QualType R = TInfo->getType();
-
   if (DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
                                       UPPC_DeclarationType))
     D.setInvalidType();
index d45c03860654142182e83c94d637aef6c0aace70..1f0dfd05a20de2313a49a38ca13bce1f7da6bc02 100644 (file)
@@ -76,13 +76,10 @@ namespace PR12629 {
 
 namespace PR12688 {
   struct S {
-    // FIXME: Producing one error saying this can't have the same name
-    //        as the class because it's not a constructor, then producing
-    //        another error saying this can't have a return type because
-    //        it is a constructor, is redundant and inconsistent.
+    // FIXME: Maybe suppress the "constructor cannot have a return type" error
+    // if the return type is invalid.
     nonsense S() throw (more_nonsense); // \
     // expected-error {{'nonsense'}} \
-    // expected-error {{has the same name as its class}} \
     // expected-error {{constructor cannot have a return type}}
   };
 }
index cc6c5af817083821b2f85d3af12a5209534dc9de..d8d9307a5ebb0b3a5c7f4ff722de13f3771edc68 100644 (file)
@@ -943,10 +943,10 @@ namespace dr188 { // dr188: yes
 namespace dr194 { // dr194: yes
   struct A {
     A();
-    void A(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}}
+    void A(); // expected-error {{constructor cannot have a return type}}
   };
   struct B {
-    void B(); // expected-error {{has the same name as its class}} expected-error {{constructor cannot have a return type}}
+    void B(); // expected-error {{constructor cannot have a return type}}
     B();
   };
   struct C {
index df24b3d0075a976c0e0aacde2856562a763d2b98..8766d861732e93ec1200cf0f59fc68fe129cf9d3 100644 (file)
@@ -19,5 +19,5 @@ struct foo {
 void baz() = delete;
 
 struct quux {
-  int quux() = default; // expected-error{{constructor cannot have a return type}} expected-error {{member 'quux' has the same name as its class}}
+  int quux() = default; // expected-error{{constructor cannot have a return type}}
 };
index fa930bdb95dcdba1b5f933395ad68e6a328b1d22..105605c6e37b44ee4f2ef5adf0ce17892e50b7a7 100644 (file)
@@ -15,8 +15,7 @@ class Foo {
   virtual Foo(double); // expected-error{{constructor cannot be declared 'virtual'}}
   Foo(long) const; // expected-error{{'const' qualifier is not allowed on a constructor}}
   
-  int Foo(int, int); // expected-error{{constructor cannot have a return type}} \
-  // expected-error{{member 'Foo' has the same name as its class}}
+  int Foo(int, int); // expected-error{{constructor cannot have a return type}}
 
   volatile Foo(float); // expected-error{{constructor cannot have a return type}}
 };