Hi rsmith,

Clang currently crashes on

    class C {
      C() = default;
      C() = delete;
    };

My cunning plan for fixing this was to change the `if (!FnD)` in 
Parser::ParseCXXInlineMethodDef() to `if (!FnD || FnD->isInvalidDecl)` – but 
alas, the second constructor decl wasn't marked as invalid. This patch lets 
Sema::MergeFunctionDecl() return true on function redeclarations, which leads 
to them being marked invalid. (There are two more diag::err_s later in the same 
function that also don't return true. These look fishy to me too – let me know 
if you think those should be changed too. Probably in a separate patch, though.)

This reduces the number of duplicate error messages in tests, which is probably 
a good thing for this kind of error – if you have two definitions of a 
function, things likely are pretty dire already.

http://reviews.llvm.org/D7021

Files:
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/Parser/DelayedTemplateParsing.cpp
  test/Parser/cxx0x-ambig.cpp
  test/SemaCXX/class.cpp
  test/SemaCXX/cxx1y-constexpr-not-const.cpp
  test/SemaCXX/cxx1y-deduced-return-type.cpp
  test/SemaCXX/overload-decl.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2761,6 +2761,7 @@
             << New << New->getType();
         }
         Diag(OldLocation, PrevDiag) << Old << Old->getType();
+        return true;
 
       // Complain if this is an explicit declaration of a special
       // member that was initially declared implicitly.
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -2159,8 +2159,10 @@
       assert(Member && "HandleField never returns null");
     }
   } else {
-    assert(InitStyle == ICIS_NoInit || D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static);
+    assert(InitStyle == ICIS_NoInit ||
+           D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static);
 
+// XXX
     Member = HandleDeclarator(S, D, TemplateParameterLists);
     if (!Member)
       return nullptr;
Index: test/Parser/DelayedTemplateParsing.cpp
===================================================================
--- test/Parser/DelayedTemplateParsing.cpp
+++ test/Parser/DelayedTemplateParsing.cpp
@@ -10,8 +10,8 @@
 
 template <class T>
 class B {
-   void foo4() { } // expected-note {{previous definition is here}}  expected-note {{previous definition is here}}
-   void foo4() { } // expected-error {{class member cannot be redeclared}} expected-error {{redefinition of 'foo4'}}
+   void foo4() { } // expected-note {{previous definition is here}}
+   void foo4() { } // expected-error {{class member cannot be redeclared}}
    void foo5() { } // expected-note {{previous definition is here}}
 
    friend void foo3() {
Index: test/Parser/cxx0x-ambig.cpp
===================================================================
--- test/Parser/cxx0x-ambig.cpp
+++ test/Parser/cxx0x-ambig.cpp
@@ -110,8 +110,8 @@
   template<typename...T>
   struct S {
     void e(S::S());
-    void f(S(...args[sizeof(T)])); // expected-note {{here}}
-    void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}} expected-note {{here}}
+    void f(S(...args[sizeof(T)])); // expected-note {{here}} expected-note {{here}}
+    void f(S(...args)[sizeof(T)]); // expected-error {{redeclared}}
     void f(S ...args[sizeof(T)]); // expected-error {{redeclared}}
     void g(S(...[sizeof(T)])); // expected-note {{here}} expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
     void g(S(...)[sizeof(T)]); // expected-error {{function cannot return array type}}
Index: test/SemaCXX/class.cpp
===================================================================
--- test/SemaCXX/class.cpp
+++ test/SemaCXX/class.cpp
@@ -119,9 +119,9 @@
 // PR5415 - don't hang!
 struct S
 {
-  void f(); // expected-note 1 {{previous declaration}}
-  void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
-  void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
+  void f(); // expected-note 1 {{previous declaration}} expected-note {{previous declaration}}
+  void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}}
+  void f() {} // expected-error {{class member cannot be redeclared}}
 };
 
 // Don't crash on this bogus code.
Index: test/SemaCXX/cxx1y-constexpr-not-const.cpp
===================================================================
--- test/SemaCXX/cxx1y-constexpr-not-const.cpp
+++ test/SemaCXX/cxx1y-constexpr-not-const.cpp
@@ -11,8 +11,6 @@
 
 // expected-error@6 {{class member cannot be redeclared}}
 // expected-note@5 {{previous}}
-// expected-error@6 {{non-constexpr declaration of 'f' follows constexpr declaration}}
-// expected-note@5 {{previous}}
 #else
 // expected-warning@5 {{'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior}}
 #endif
Index: test/SemaCXX/cxx1y-deduced-return-type.cpp
===================================================================
--- test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -21,8 +21,8 @@
 int conv1d = conv1.operator int(); // expected-error {{no member named 'operator int'}}
 
 struct Conv2 {
-  operator auto() { return 0; }  // expected-note 2{{previous}}
-  operator auto() { return 0.; } // expected-error {{cannot be redeclared}} expected-error {{redefinition of 'operator auto'}}
+  operator auto() { return 0; }  // expected-note {{previous}}
+  operator auto() { return 0.; } // expected-error {{cannot be redeclared}}
 };
 
 struct Conv3 {
Index: test/SemaCXX/overload-decl.cpp
===================================================================
--- test/SemaCXX/overload-decl.cpp
+++ test/SemaCXX/overload-decl.cpp
@@ -30,10 +30,8 @@
   static void g(int); // expected-error {{static and non-static member functions with the same parameter types cannot be overloaded}}
   static void g(float); // expected-error {{class member cannot be redeclared}}
 
-  void h(); // expected-note {{previous declaration is here}} \
-               expected-note {{previous declaration is here}}
-  void h() __restrict; // expected-error {{class member cannot be redeclared}} \
-                          expected-error {{conflicting types for 'h'}}
+  void h(); // expected-note {{previous declaration is here}}
+  void h() __restrict; // expected-error {{class member cannot be redeclared}}
 };
 
 int main() {} // expected-note {{previous definition is here}}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to