r226365 - If a function decl cannot be merged, mark it as invalid.
Nico Weber
thakis at chromium.org
Fri Jan 16 20:17:19 PST 2015
On Fri, Jan 16, 2015 at 6:33 PM, Nico Weber <nicolasweber at gmx.de> wrote:
> Author: nico
> Date: Fri Jan 16 20:33:17 2015
> New Revision: 226365
>
> URL: http://llvm.org/viewvc/llvm-project?rev=226365&view=rev
> Log:
> If a function decl cannot be merged, mark it as invalid.
>
> Clang currently crashes on
>
> class C {
> C() = default;
> C() = delete;
> };
>
This is wrong. clang used to crash when these two lines were swapped.
Anyhow, my cunning plan wasn't necessary: This change was enough to fix the
crash. I added a test for this in r226370.
>
> 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 lets
> Sema::MergeFunctionDecl() return true on function redeclarations, which
> leads
> to them being marked invalid.
>
> This also improves error messages when functions are redeclared.
>
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
> cfe/trunk/test/Parser/cxx0x-ambig.cpp
> cfe/trunk/test/SemaCXX/class.cpp
> cfe/trunk/test/SemaCXX/cxx1y-constexpr-not-const.cpp
> cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
> cfe/trunk/test/SemaCXX/overload-decl.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 16 20:33:17 2015
> @@ -2761,6 +2761,7 @@ bool Sema::MergeFunctionDecl(FunctionDec
> << 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.
>
> Modified: cfe/trunk/test/Parser/DelayedTemplateParsing.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/DelayedTemplateParsing.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Parser/DelayedTemplateParsing.cpp (original)
> +++ cfe/trunk/test/Parser/DelayedTemplateParsing.cpp Fri Jan 16 20:33:17
> 2015
> @@ -10,8 +10,8 @@ class A {
>
> 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() {
>
> Modified: cfe/trunk/test/Parser/cxx0x-ambig.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-ambig.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Parser/cxx0x-ambig.cpp (original)
> +++ cfe/trunk/test/Parser/cxx0x-ambig.cpp Fri Jan 16 20:33:17 2015
> @@ -110,8 +110,8 @@ namespace ellipsis {
> 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}}
>
> Modified: cfe/trunk/test/SemaCXX/class.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/class.cpp (original)
> +++ cfe/trunk/test/SemaCXX/class.cpp Fri Jan 16 20:33:17 2015
> @@ -119,9 +119,9 @@ struct C4 {
> // 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.
>
> Modified: cfe/trunk/test/SemaCXX/cxx1y-constexpr-not-const.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-constexpr-not-const.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/cxx1y-constexpr-not-const.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx1y-constexpr-not-const.cpp Fri Jan 16
> 20:33:17 2015
> @@ -11,8 +11,6 @@ struct X {
>
> // expected-error at 6 {{class member cannot be redeclared}}
> // expected-note at 5 {{previous}}
> -// expected-error at 6 {{non-constexpr declaration of 'f' follows constexpr
> declaration}}
> -// expected-note at 5 {{previous}}
> #else
> // expected-warning at 5 {{'constexpr' non-static member function will not
> be implicitly 'const' in C++14; add 'const' to avoid a change in behavior}}
> #endif
>
> Modified: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Fri Jan 16
> 20:33:17 2015
> @@ -21,8 +21,8 @@ int conv1c = conv1.operator auto();
> 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}} expected-error {{cannot initialize return object of type
> 'auto' with an rvalue of type 'double'}}
> };
>
> struct Conv3 {
>
> Modified: cfe/trunk/test/SemaCXX/overload-decl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overload-decl.cpp?rev=226365&r1=226364&r2=226365&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/overload-decl.cpp (original)
> +++ cfe/trunk/test/SemaCXX/overload-decl.cpp Fri Jan 16 20:33:17 2015
> @@ -30,10 +30,8 @@ class X {
> 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
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150116/b47f8d94/attachment.html>
More information about the cfe-commits
mailing list