From ea5092a3b05ef184f0f73ccb8a4820740f0c2744 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 7 Jul 2013 23:49:50 +0000 Subject: Sema: Do not merge new decls with invalid, old decls Sema::MergeFunctionDecl attempts merging two decls even if the old decl is invalid. This can lead to interesting circumstances where we successfully merge the decls but the result makes no sense. Take the following for example: template int main(void); int main(void); Sema will not consider these to be overloads of the same name because main can't be overloaded, which means that this must be a redeclaration. In this case the templated decl is compatible with the non-templated decl allowing the Sema::CheckFunctionDeclaration machinery to move on and do bizarre things like setting the previous decl of a non-templated decl to a templated decl! The way I see it, we should just bail from MergeFunctionDecl if the old decl is invalid. This fixes PR16531. llvm-svn: 185779 --- clang/test/Parser/DelayedTemplateParsing.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'clang/test/Parser/DelayedTemplateParsing.cpp') diff --git a/clang/test/Parser/DelayedTemplateParsing.cpp b/clang/test/Parser/DelayedTemplateParsing.cpp index 77b47239f4c..3e429d41162 100644 --- a/clang/test/Parser/DelayedTemplateParsing.cpp +++ b/clang/test/Parser/DelayedTemplateParsing.cpp @@ -11,7 +11,8 @@ class A { template 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'}} expected-note {{previous definition is here}} + void foo4() { } // expected-error {{class member cannot be redeclared}} expected-error {{redefinition of 'foo4'}} + void foo5() { } // expected-note {{previous definition is here}} friend void foo3() { undeclared(); @@ -20,7 +21,7 @@ class B { template -void B::foo4() {// expected-error {{redefinition of 'foo4'}} +void B::foo5() { // expected-error {{redefinition of 'foo5'}} } template -- cgit v1.2.3