Add a flag to BuildDeclarationNameExpr to not reject invalid decls.

llvm-svn: 222463
This commit is contained in:
Kaelyn Takata 2014-11-20 22:06:33 +00:00
parent 3f9794f288
commit 6f71ce2e21
3 changed files with 14 additions and 10 deletions

View File

@ -3529,11 +3529,13 @@ public:
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS,
LookupResult &R, LookupResult &R,
bool NeedsADL); bool NeedsADL,
bool AcceptInvalidDecl = false);
ExprResult BuildDeclarationNameExpr( ExprResult BuildDeclarationNameExpr(
const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
NamedDecl *FoundD = nullptr, NamedDecl *FoundD = nullptr,
const TemplateArgumentListInfo *TemplateArgs = nullptr); const TemplateArgumentListInfo *TemplateArgs = nullptr,
bool AcceptInvalidDecl = false);
ExprResult BuildLiteralOperatorCall(LookupResult &R, ExprResult BuildLiteralOperatorCall(LookupResult &R,
DeclarationNameInfo &SuffixInfo, DeclarationNameInfo &SuffixInfo,

View File

@ -2613,15 +2613,15 @@ static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D) {
return false; return false;
} }
ExprResult ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL,
LookupResult &R, bool AcceptInvalidDecl) {
bool NeedsADL) {
// If this is a single, fully-resolved result and we don't need ADL, // If this is a single, fully-resolved result and we don't need ADL,
// just build an ordinary singleton decl ref. // just build an ordinary singleton decl ref.
if (!NeedsADL && R.isSingleResult() && !R.getAsSingle<FunctionTemplateDecl>()) if (!NeedsADL && R.isSingleResult() && !R.getAsSingle<FunctionTemplateDecl>())
return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), R.getFoundDecl(), return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), R.getFoundDecl(),
R.getRepresentativeDecl()); R.getRepresentativeDecl(), nullptr,
AcceptInvalidDecl);
// We only need to check the declaration if there's exactly one // We only need to check the declaration if there's exactly one
// result, because in the overloaded case the results can only be // result, because in the overloaded case the results can only be
@ -2648,7 +2648,8 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
/// \brief Complete semantic analysis for a reference to the given declaration. /// \brief Complete semantic analysis for a reference to the given declaration.
ExprResult Sema::BuildDeclarationNameExpr( ExprResult Sema::BuildDeclarationNameExpr(
const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D,
NamedDecl *FoundD, const TemplateArgumentListInfo *TemplateArgs) { NamedDecl *FoundD, const TemplateArgumentListInfo *TemplateArgs,
bool AcceptInvalidDecl) {
assert(D && "Cannot refer to a NULL declaration"); assert(D && "Cannot refer to a NULL declaration");
assert(!isa<FunctionTemplateDecl>(D) && assert(!isa<FunctionTemplateDecl>(D) &&
"Cannot refer unambiguously to a function template"); "Cannot refer unambiguously to a function template");
@ -2683,7 +2684,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
return ExprError(); return ExprError();
// Only create DeclRefExpr's for valid Decl's. // Only create DeclRefExpr's for valid Decl's.
if (VD->isInvalidDecl()) if (VD->isInvalidDecl() && !AcceptInvalidDecl)
return ExprError(); return ExprError();
// Handle members of anonymous structs and unions. If we got here, // Handle members of anonymous structs and unions. If we got here,

View File

@ -5971,7 +5971,8 @@ static ExprResult attemptRecovery(Sema &SemaRef,
} }
} }
return SemaRef.BuildDeclarationNameExpr(NewSS, R, false); return SemaRef.BuildDeclarationNameExpr(NewSS, R, /*NeedsADL*/ false,
/*AcceptInvalidDecl*/ true);
} }
namespace { namespace {