PR13775: When checking for a tag type being shadowed by some other declaration,
don't trample over the caller's LookupResult in the case where the check fails. llvm-svn: 163281
This commit is contained in:
parent
30c4282f88
commit
aa31b4b816
|
@ -518,9 +518,9 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
|
||||||
Scope *S, CXXScopeSpec &SS,
|
Scope *S, CXXScopeSpec &SS,
|
||||||
IdentifierInfo *&Name,
|
IdentifierInfo *&Name,
|
||||||
SourceLocation NameLoc) {
|
SourceLocation NameLoc) {
|
||||||
Result.clear(Sema::LookupTagName);
|
LookupResult R(SemaRef, Name, NameLoc, Sema::LookupTagName);
|
||||||
SemaRef.LookupParsedName(Result, S, &SS);
|
SemaRef.LookupParsedName(R, S, &SS);
|
||||||
if (TagDecl *Tag = Result.getAsSingle<TagDecl>()) {
|
if (TagDecl *Tag = R.getAsSingle<TagDecl>()) {
|
||||||
const char *TagName = 0;
|
const char *TagName = 0;
|
||||||
const char *FixItTagName = 0;
|
const char *FixItTagName = 0;
|
||||||
switch (Tag->getTagKind()) {
|
switch (Tag->getTagKind()) {
|
||||||
|
@ -554,17 +554,17 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
|
||||||
<< Name << TagName << SemaRef.getLangOpts().CPlusPlus
|
<< Name << TagName << SemaRef.getLangOpts().CPlusPlus
|
||||||
<< FixItHint::CreateInsertion(NameLoc, FixItTagName);
|
<< FixItHint::CreateInsertion(NameLoc, FixItTagName);
|
||||||
|
|
||||||
LookupResult R(SemaRef, Name, NameLoc, Sema::LookupOrdinaryName);
|
for (LookupResult::iterator I = Result.begin(), IEnd = Result.end();
|
||||||
if (SemaRef.LookupParsedName(R, S, &SS)) {
|
I != IEnd; ++I)
|
||||||
for (LookupResult::iterator I = R.begin(), IEnd = R.end();
|
SemaRef.Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
|
||||||
I != IEnd; ++I)
|
<< Name << TagName;
|
||||||
SemaRef.Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
|
|
||||||
<< Name << TagName;
|
// Replace lookup results with just the tag decl.
|
||||||
}
|
Result.clear(Sema::LookupTagName);
|
||||||
|
SemaRef.LookupParsedName(Result, S, &SS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result.clear(Sema::LookupOrdinaryName);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,14 +862,12 @@ Corrected:
|
||||||
if ((NextToken.is(tok::identifier) ||
|
if ((NextToken.is(tok::identifier) ||
|
||||||
(NextIsOp && FirstDecl->isFunctionOrFunctionTemplate())) &&
|
(NextIsOp && FirstDecl->isFunctionOrFunctionTemplate())) &&
|
||||||
isTagTypeWithMissingTag(*this, Result, S, SS, Name, NameLoc)) {
|
isTagTypeWithMissingTag(*this, Result, S, SS, Name, NameLoc)) {
|
||||||
FirstDecl = (*Result.begin())->getUnderlyingDecl();
|
TypeDecl *Type = Result.getAsSingle<TypeDecl>();
|
||||||
if (TypeDecl *Type = dyn_cast<TypeDecl>(FirstDecl)) {
|
DiagnoseUseOfDecl(Type, NameLoc);
|
||||||
DiagnoseUseOfDecl(Type, NameLoc);
|
QualType T = Context.getTypeDeclType(Type);
|
||||||
QualType T = Context.getTypeDeclType(Type);
|
if (SS.isNotEmpty())
|
||||||
if (SS.isNotEmpty())
|
return buildNestedType(*this, SS, T, NameLoc);
|
||||||
return buildNestedType(*this, SS, T, NameLoc);
|
return ParsedType::make(T);
|
||||||
return ParsedType::make(T);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,20 @@ namespace ctor_error {
|
||||||
// expected-error{{unknown type name 'UnknownType'}}
|
// expected-error{{unknown type name 'UnknownType'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PR13775: Don't assert here.
|
||||||
|
namespace PR13775 {
|
||||||
|
class bar
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void foo ();
|
||||||
|
void baz ();
|
||||||
|
};
|
||||||
|
void bar::foo ()
|
||||||
|
{
|
||||||
|
baz x(); // expected-error 3{{}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PR11109 must appear at the end of the source file
|
// PR11109 must appear at the end of the source file
|
||||||
class pr11109r3 { // expected-note{{to match this '{'}}
|
class pr11109r3 { // expected-note{{to match this '{'}}
|
||||||
public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}
|
public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}
|
||||||
|
|
Loading…
Reference in New Issue