Skip to content

Commit aa41e28

Browse files
committed
[FOLD] discard invalid nested-name-specifiers
1 parent 2d8a137 commit aa41e28

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

clang/include/clang/Sema/Lookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ class LookupResult {
496496
/// Note that while no result was found in the current instantiation,
497497
/// there were dependent base classes that could not be searched.
498498
void setNotFoundInCurrentInstantiation() {
499-
assert(ResultKind == NotFound && Decls.empty());
499+
assert((ResultKind == NotFound || ResultKind == NotFoundInCurrentInstantiation) && Decls.empty());
500500
ResultKind = NotFoundInCurrentInstantiation;
501501
}
502502

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,9 @@ ExprResult Sema::BuildMemberReferenceExpr(
815815
ActOnMemberAccessExtraArgs *ExtraArgs) {
816816
LookupResult R(*this, NameInfo, LookupMemberName);
817817

818+
if (SS.isInvalid())
819+
SS.clear();
820+
818821
// Implicit member accesses.
819822
if (!Base) {
820823
TypoExpr *TE = nullptr;
@@ -1014,7 +1017,7 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
10141017
const Scope *S,
10151018
bool SuppressQualifierCheck,
10161019
ActOnMemberAccessExtraArgs *ExtraArgs) {
1017-
1020+
assert(!SS.isInvalid() && "nested-name-specifier cannot be invalid");
10181021
if (R.wasNotFoundInCurrentInstantiation() ||
10191022
(SS.isValid() && !computeDeclContext(SS, false))) {
10201023
return ActOnDependentMemberExpr(BaseExpr, BaseExprType, IsArrow, OpLoc, SS,
@@ -1059,7 +1062,8 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
10591062
if (R.empty()) {
10601063
// Rederive where we looked up.
10611064
DeclContext *DC = (SS.isSet() ? computeDeclContext(SS, false)
1062-
: BaseType->getAsRecordDecl());
1065+
: computeDeclContext(BaseType));
1066+
// : BaseType->getAsRecordDecl());
10631067

10641068
if (ExtraArgs) {
10651069
ExprResult RetryExpr;
@@ -1086,7 +1090,10 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
10861090
}
10871091
}
10881092

1089-
if (DC) {
1093+
if (SS.isInvalid() || (SS.isNotEmpty() && !DC)) {
1094+
Diag(R.getNameLoc(), diag::err_undeclared_use)
1095+
<< MemberName << SS.getRange();
1096+
} else if (DC) {
10901097
Diag(R.getNameLoc(), diag::err_no_member)
10911098
<< MemberName << DC
10921099
<< (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
@@ -1096,6 +1103,16 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
10961103
<< MemberName << BaseExprType
10971104
<< (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
10981105
}
1106+
1107+
if (DC) {
1108+
} else {
1109+
#if 0
1110+
// FIXME: Is this needed?
1111+
Diag(R.getNameLoc(), diag::err_no_member)
1112+
<< MemberName << BaseExprType
1113+
<< (BaseExpr ? BaseExpr->getSourceRange() : SourceRange());
1114+
#endif
1115+
}
10991116
return ExprError();
11001117
}
11011118

0 commit comments

Comments
 (0)