[cfe-commits] r152470 - in /cfe/trunk: lib/AST/DeclCXX.cpp test/CodeGenCXX/inheriting-constructor.cpp
Eli Friedman
eli.friedman at gmail.com
Fri Mar 9 17:39:01 PST 2012
Author: efriedma
Date: Fri Mar 9 19:39:01 2012
New Revision: 152470
URL: http://llvm.org/viewvc/llvm-project?rev=152470&view=rev
Log:
Make sure the accessors for overridden methods don't return inherited constructors. Fixes PR12219.
Added:
cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp
Modified:
cfe/trunk/lib/AST/DeclCXX.cpp
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=152470&r1=152469&r2=152470&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Mar 9 19:39:01 2012
@@ -1421,19 +1421,23 @@
assert(MD->isCanonicalDecl() && "Method is not canonical!");
assert(!MD->getParent()->isDependentContext() &&
"Can't add an overridden method to a class template!");
+ assert(MD->isVirtual() && "Method is not virtual!");
getASTContext().addOverriddenMethod(this, MD);
}
CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const {
+ if (isa<CXXConstructorDecl>(this)) return 0;
return getASTContext().overridden_methods_begin(this);
}
CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const {
+ if (isa<CXXConstructorDecl>(this)) return 0;
return getASTContext().overridden_methods_end(this);
}
unsigned CXXMethodDecl::size_overridden_methods() const {
+ if (isa<CXXConstructorDecl>(this)) return 0;
return getASTContext().overridden_methods_size(this);
}
@@ -1712,8 +1716,8 @@
const CXXConstructorDecl *CXXConstructorDecl::getInheritedConstructor() const {
// Hack: we store the inherited constructor in the overridden method table
- method_iterator It = begin_overridden_methods();
- if (It == end_overridden_methods())
+ method_iterator It = getASTContext().overridden_methods_begin(this);
+ if (It == getASTContext().overridden_methods_end(this))
return 0;
return cast<CXXConstructorDecl>(*It);
@@ -1722,8 +1726,9 @@
void
CXXConstructorDecl::setInheritedConstructor(const CXXConstructorDecl *BaseCtor){
// Hack: we store the inherited constructor in the overridden method table
- assert(size_overridden_methods() == 0 && "Base ctor already set.");
- addOverriddenMethod(BaseCtor);
+ assert(getASTContext().overridden_methods_size(this) == 0 &&
+ "Base ctor already set.");
+ getASTContext().addOverriddenMethod(this, BaseCtor);
}
void CXXDestructorDecl::anchor() { }
Added: cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp?rev=152470&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/inheriting-constructor.cpp Fri Mar 9 19:39:01 2012
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+
+// PR12219
+struct A { A(int); virtual ~A(); };
+struct B : A { using A::A; ~B(); };
+B::~B() {}
+// CHECK: define void @_ZN1BD0Ev
+// CHECK: define void @_ZN1BD1Ev
+// CHECK: define void @_ZN1BD2Ev
More information about the cfe-commits
mailing list