aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-14 00:46:47 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-04-14 00:46:47 +0000
commit0d8dc460ae02e29d0b2abb4d6d093736e2f920ea (patch)
tree436c2fb3d20a8c7129be1c2bacd588d287dd71ff /lib/Sema/SemaExpr.cpp
parentfb67ccd9da412d652d62e2ac9675b0f1b14fdc73 (diff)
When creating an implicit member expression through a qualified-id, check that the class
named by the nested-name-specifier is same or base of the class in which the member expression appears. It seems we also had an ill-formed test case, mon dieu! Fixes rdar://8576107. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index eb84cff999..8ccb9b8180 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1318,12 +1318,24 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
return IMA_Error_StaticContext;
}
+ CXXRecordDecl *
+ contextClass = cast<CXXMethodDecl>(DC)->getParent()->getCanonicalDecl();
+
+ // [class.mfct.non-static]p3:
+ // ...is used in the body of a non-static member function of class X,
+ // if name lookup (3.4.1) resolves the name in the id-expression to a
+ // non-static non-type member of some class C [...]
+ // ...if C is not X or a base class of X, the class member access expression
+ // is ill-formed.
+ if (R.getNamingClass() &&
+ contextClass != R.getNamingClass()->getCanonicalDecl() &&
+ contextClass->isProvablyNotDerivedFrom(R.getNamingClass()))
+ return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated);
+
// If we can prove that the current context is unrelated to all the
// declaring classes, it can't be an implicit member reference (in
// which case it's an error if any of those members are selected).
- if (IsProvablyNotDerivedFrom(SemaRef,
- cast<CXXMethodDecl>(DC)->getParent(),
- Classes))
+ if (IsProvablyNotDerivedFrom(SemaRef, contextClass, Classes))
return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated);
return (hasNonInstance ? IMA_Mixed : IMA_Instance);