Fix a crash with qualified member access into a non-type, from Sean Hunt!

llvm-svn: 84370
This commit is contained in:
Douglas Gregor 2009-10-17 22:37:54 +00:00
parent a1944d704e
commit 0b3d95ae64
3 changed files with 19 additions and 0 deletions

View File

@ -383,6 +383,8 @@ def note_ambig_member_ref_object_type : Note<
"lookup in the object type %0 refers here">;
def note_ambig_member_ref_scope : Note<
"lookup from the current scope refers here">;
def err_qualified_member_nonclass : Error<
"qualified member access refers to a member in %0">;
// C++ class members
def err_storageclass_invalid_for_member : Error<

View File

@ -2184,6 +2184,12 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
// If the member name was a qualified-id, look into the
// nested-name-specifier.
DC = computeDeclContext(*SS, false);
if (!isa<TypeDecl>(DC)) {
Diag(MemberLoc, diag::err_qualified_member_nonclass)
<< DC << SS->getRange();
return ExprError();
}
// FIXME: If DC is not computable, we should build a
// CXXUnresolvedMemberExpr.

View File

@ -31,3 +31,14 @@ int f0(B *b) {
return b->f0->f0; // expected-error{{member reference base type 'struct A *()' is not a structure or union}} \
// expected-note{{perhaps you meant to call this function}}
}
int i;
namespace C {
int i;
}
void test2(X *xp) {
xp->::i = 7; // expected-error{{qualified member access refers to a member in the global namespace}}
xp->C::i = 7; // expected-error{{qualified member access refers to a member in namespace 'C'}}
}