Skip to content

Commit

Permalink
[clang] Fix a null-NSS-access crash in DependentNameType.
Browse files Browse the repository at this point in the history
The DependentNameType must have a non-null NSS. This property could be
violated during typo correction.

Differential Revision: https://reviews.llvm.org/D82738
  • Loading branch information
hokein committed Jul 2, 2020
1 parent d6343e6 commit 8c5133f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4844,10 +4844,7 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
CXXScopeSpec SS;
DeclarationNameInfo NameInfo;

if (DeclRefExpr *ArgExpr = dyn_cast<DeclRefExpr>(Arg.getAsExpr())) {
SS.Adopt(ArgExpr->getQualifierLoc());
NameInfo = ArgExpr->getNameInfo();
} else if (DependentScopeDeclRefExpr *ArgExpr =
if (DependentScopeDeclRefExpr *ArgExpr =
dyn_cast<DependentScopeDeclRefExpr>(Arg.getAsExpr())) {
SS.Adopt(ArgExpr->getQualifierLoc());
NameInfo = ArgExpr->getNameInfo();
Expand All @@ -4866,6 +4863,7 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
if (Result.getAsSingle<TypeDecl>() ||
Result.getResultKind() ==
LookupResult::NotFoundInCurrentInstantiation) {
assert(SS.getScopeRep() && "dependent scope expr must has a scope!");
// Suggest that the user add 'typename' before the NNS.
SourceLocation Loc = AL.getSourceRange().getBegin();
Diag(Loc, getLangOpts().MSVCCompat
Expand Down
14 changes: 14 additions & 0 deletions clang/test/Parser/cxx-template-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,17 @@ namespace PR45239 {
template<int> int b;
template<int> auto f() -> b<0>; // expected-error +{{}}
}

namespace NoCrashOnNullNNSTypoCorrection {

int AddObservation(); // expected-note {{declared here}}

template <typename T, typename... Args> // expected-note {{template parameter is declared here}}
class UsingImpl {};
class AddObservation {
using Using =
UsingImpl<AddObservationFn, const int>; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} \
expected-error {{template argument for template type parameter must be a type}}
};

}

0 comments on commit 8c5133f

Please sign in to comment.