[cfe-commits] r72601 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaInherit.cpp lib/Sema/SemaInherit.h test/SemaCXX/abstract.cpp
Anders Carlsson
andersca at mac.com
Fri May 29 17:52:53 PDT 2009
Author: andersca
Date: Fri May 29 19:52:53 2009
New Revision: 72601
URL: http://llvm.org/viewvc/llvm-project?rev=72601&view=rev
Log:
Add a member lookup criteria constructor for searching for overridden virtual member functions. Use this instead of regular name lookup when checking for overriding functions so we will see declarations that would otherwise be hidden. Fixes 6902298.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaInherit.cpp
cfe/trunk/lib/Sema/SemaInherit.h
cfe/trunk/test/SemaCXX/abstract.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=72601&r1=72600&r2=72601&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May 29 19:52:53 2009
@@ -2145,23 +2145,11 @@
// Look for virtual methods in base classes that this method might override.
BasePaths Paths;
- // FIXME: This will not include hidden member functions.
if (LookupInBases(cast<CXXRecordDecl>(DC),
- MemberLookupCriteria(Name, LookupMemberName,
- // FIXME: Shouldn't IDNS_Member be
- // enough here?
- Decl::IDNS_Member |
- Decl::IDNS_Ordinary), Paths)) {
+ MemberLookupCriteria(NewMD), Paths)) {
for (BasePaths::decl_iterator I = Paths.found_decls_begin(),
E = Paths.found_decls_end(); I != E; ++I) {
if (CXXMethodDecl *OldMD = dyn_cast<CXXMethodDecl>(*I)) {
- OverloadedFunctionDecl::function_iterator MatchedDecl;
- // FIXME: Is this OK? Should it be done by LookupInBases?
- if (IsOverload(NewMD, OldMD, MatchedDecl))
- continue;
- if (!OldMD->isVirtual())
- continue;
-
if (!CheckOverridingFunctionReturnType(NewMD, OldMD))
NewMD->addOverriddenMethod(OldMD);
}
Modified: cfe/trunk/lib/Sema/SemaInherit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInherit.cpp?rev=72601&r1=72600&r2=72601&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInherit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInherit.cpp Fri May 29 19:52:53 2009
@@ -191,6 +191,22 @@
++Paths.ScratchPath.Decls.first;
}
break;
+ case MemberLookupCriteria::LK_OverriddenMember:
+ Paths.ScratchPath.Decls =
+ BaseRecord->lookup(Context, Criteria.Method->getDeclName());
+ while (Paths.ScratchPath.Decls.first != Paths.ScratchPath.Decls.second) {
+ CXXMethodDecl *MD =
+ cast<CXXMethodDecl>(*Paths.ScratchPath.Decls.first);
+
+ OverloadedFunctionDecl::function_iterator MatchedDecl;
+ if (MD->isVirtual() && !IsOverload(Criteria.Method, MD, MatchedDecl)) {
+ FoundPathToThisBase = true;
+ break;
+ }
+
+ ++Paths.ScratchPath.Decls.first;
+ }
+ break;
}
if (FoundPathToThisBase) {
Modified: cfe/trunk/lib/Sema/SemaInherit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInherit.h?rev=72601&r1=72600&r2=72601&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInherit.h (original)
+++ cfe/trunk/lib/Sema/SemaInherit.h Fri May 29 19:52:53 2009
@@ -205,7 +205,8 @@
/// LookupKind - the kind of lookup we're doing.
enum LookupKind {
LK_Base,
- LK_NamedMember
+ LK_NamedMember,
+ LK_OverriddenMember
};
/// MemberLookupCriteria - Constructs member lookup criteria to
@@ -220,6 +221,9 @@
unsigned IDNS)
: Kind(LK_NamedMember), Name(Name), NameKind(NameKind), IDNS(IDNS) { }
+ explicit MemberLookupCriteria(CXXMethodDecl *MD)
+ : Kind(LK_OverriddenMember), Method(MD) { }
+
/// Kind - The kind of lookup we're doing.
/// LK_Base if we are looking for a base class (whose
/// type is Base). LK_NamedMember if we are looking for a named member of
@@ -236,6 +240,8 @@
Sema::LookupNameKind NameKind;
unsigned IDNS;
+
+ CXXMethodDecl *Method;
};
}
Modified: cfe/trunk/test/SemaCXX/abstract.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/abstract.cpp?rev=72601&r1=72600&r2=72601&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/abstract.cpp (original)
+++ cfe/trunk/test/SemaCXX/abstract.cpp Fri May 29 19:52:53 2009
@@ -95,3 +95,26 @@
};
bar x;
+
+// <rdar://problem/6902298>
+class A
+{
+public:
+ virtual void release() = 0;
+ virtual void release(int count) = 0;
+ virtual void retain() = 0;
+};
+
+class B : public A
+{
+public:
+ virtual void release();
+ virtual void release(int count);
+ virtual void retain();
+};
+
+void foo(void)
+{
+ B b;
+}
+
More information about the cfe-commits
mailing list