[cfe-commits] r89777 - in /cfe/trunk: include/clang/AST/Redeclarable.h test/SemaCXX/class.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Tue Nov 24 09:14:35 PST 2009
Author: cornedbee
Date: Tue Nov 24 11:14:34 2009
New Revision: 89777
URL: http://llvm.org/viewvc/llvm-project?rev=89777&view=rev
Log:
Make sure redeclaration chains are properly linked, even through invalid decls. This fixes PR5415.
Modified:
cfe/trunk/include/clang/AST/Redeclarable.h
cfe/trunk/test/SemaCXX/class.cpp
Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=89777&r1=89776&r2=89777&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Tue Nov 24 11:14:34 2009
@@ -92,6 +92,11 @@
}
/// \brief Returns the most recent (re)declaration of this declaration.
+ decl_type *getMostRecentDeclaration() {
+ return getFirstDeclaration()->RedeclLink.getNext();
+ }
+
+ /// \brief Returns the most recent (re)declaration of this declaration.
const decl_type *getMostRecentDeclaration() const {
return getFirstDeclaration()->RedeclLink.getNext();
}
@@ -102,8 +107,11 @@
decl_type *First;
if (PrevDecl) {
- // Point to previous.
- RedeclLink = PreviousDeclLink(PrevDecl);
+ // Point to previous. Make sure that this is actually the most recent
+ // redeclaration, or we can build invalid chains. If the most recent
+ // redeclaration is invalid, it won't be PrevDecl, but we want it anyway.
+ RedeclLink = PreviousDeclLink(cast<decl_type>(
+ PrevDecl->getMostRecentDeclaration()));
First = PrevDecl->getFirstDeclaration();
assert(First->RedeclLink.NextIsLatest() && "Expected first");
} else {
Modified: cfe/trunk/test/SemaCXX/class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class.cpp?rev=89777&r1=89776&r2=89777&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/class.cpp (original)
+++ cfe/trunk/test/SemaCXX/class.cpp Tue Nov 24 11:14:34 2009
@@ -110,3 +110,12 @@
void f(); // expected-note{{previous declaration is here}}
int f; // expected-error{{duplicate member 'f'}}
};
+
+// PR5415 - don't hang!
+struct S
+{
+ void f(); // expected-note 2 {{previous declaration}}
+ // FIXME: the out-of-line error shouldn't be there
+ void S::f() {} // expected-error {{class member cannot be redeclared}} expected-error {{out-of-line}} expected-note {{previous definition}}
+ void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
+};
More information about the cfe-commits
mailing list