Skip to content

Commit

Permalink
Fix crash when '^::' is used as a default template argument.
Browse files Browse the repository at this point in the history
Also fixes an issue for which a qualified-id whose leading component is
a splice could be interpreted as a dependent member expression.

Closes issue #35.
  • Loading branch information
katzdm committed Apr 30, 2024
1 parent b6e7243 commit f247b56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,14 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,

// Check if the nested name specifier is an enum type.
bool IsEnum = false;
if (NestedNameSpecifier *NNS = SS.getScopeRep())
bool HasLeadingSplice = false;
if (NestedNameSpecifier *NNS = SS.getScopeRep()) {
IsEnum = isa_and_nonnull<EnumType>(NNS->getAsType());
HasLeadingSplice = NNS->getAsSpliceExpr();
}

if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
isa<CXXMethodDecl>(DC) &&
!HasLeadingSplice && isa<CXXMethodDecl>(DC) &&
cast<CXXMethodDecl>(DC)->isImplicitObjectMemberFunction()) {
QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType().getNonReferenceType();

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,8 @@ getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
if (!D)
return nullptr;
if (isa<TranslationUnitDecl>(D))
return D;

if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Reflection/lift-operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ constexpr info info_nonstructural = ^Nonstructural{42};

namespace ns {}
constexpr info info_ns = ^ns;

// =======================================
// bb_clang_p2996_issue_35_regression_test
// =======================================

namespace bb_clang_p2996_issue_35_regression_test {
template <auto R = ^::> class S {};
S s;
} // namespace bb_clang_p2996_issue_35_regression_test

0 comments on commit f247b56

Please sign in to comment.