Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ Bug Fixes in This Version
first parameter. (#GH113323).
- Fixed a crash with incompatible pointer to integer conversions in designated
initializers involving string literals. (#GH154046)
- Fix crash on CTAD for alias template. (#GH131342)
- Clang now emits a frontend error when a function marked with the `flatten` attribute
calls another function that requires target features not enabled in the caller. This
prevents a fatal error in the backend.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4714,7 +4714,7 @@ class SubstNonTypeTemplateParmExpr : public Expr {
// sugared: it doesn't need to be resugared later.
bool getFinal() const { return Final; }

NamedDecl *getParameter() const;
NonTypeTemplateParmDecl *getParameter() const;

bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); }

Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/AST/TypeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,9 @@ class AdjustedType : public Type, public llvm::FoldingSetNode {

AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
QualType CanonicalPtr)
: Type(TC, CanonicalPtr, OriginalTy->getDependence()),
: Type(TC, CanonicalPtr,
AdjustedTy->getDependence() |
(OriginalTy->getDependence() & ~TypeDependence::Dependent)),
OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}

public:
Expand Down
17 changes: 17 additions & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11714,6 +11714,23 @@ class Sema final : public SemaBase {
const TemplateArgumentListInfo *TemplateArgs,
bool IsAddressOfOperand);

UnsignedOrNone getPackIndex(TemplateArgument Pack) const {
return Pack.pack_size() - 1 - *ArgPackSubstIndex;
}

TemplateArgument
getPackSubstitutedTemplateArgument(TemplateArgument Arg) const {
Arg = Arg.pack_elements()[*ArgPackSubstIndex];
if (Arg.isPackExpansion())
Arg = Arg.getPackExpansionPattern();
return Arg;
}

ExprResult BuildSubstNonTypeTemplateParmExpr(
Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP,
SourceLocation loc, TemplateArgument Replacement,
UnsignedOrNone PackIndex, bool Final);

/// Form a template name from a name that is syntactically required to name a
/// template, either due to use of the 'template' keyword or because a name in
/// this syntactic context is assumed to name a template (C++
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,8 @@ SizeOfPackExpr *SizeOfPackExpr::CreateDeserialized(ASTContext &Context,
return new (Storage) SizeOfPackExpr(EmptyShell(), NumPartialArgs);
}

NamedDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
return cast<NamedDecl>(
NonTypeTemplateParmDecl *SubstNonTypeTemplateParmExpr::getParameter() const {
return cast<NonTypeTemplateParmDecl>(
getReplacedTemplateParameterList(getAssociatedDecl())->asArray()[Index]);
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/StmtProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,8 @@ void StmtProfiler::VisitExpr(const Expr *S) {
}

void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
VisitExpr(S);
// Profile exactly as the sub-expression.
Visit(S->getSubExpr());
}

void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Expand Down
34 changes: 34 additions & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,40 @@ Sema::BuildDependentDeclRefExpr(const CXXScopeSpec &SS,
TemplateArgs);
}

ExprResult Sema::BuildSubstNonTypeTemplateParmExpr(
Decl *AssociatedDecl, const NonTypeTemplateParmDecl *NTTP,
SourceLocation Loc, TemplateArgument Arg, UnsignedOrNone PackIndex,
bool Final) {
// The template argument itself might be an expression, in which case we just
// return that expression. This happens when substituting into an alias
// template.
Expr *Replacement;
bool refParam = true;
if (Arg.getKind() == TemplateArgument::Expression) {
Replacement = Arg.getAsExpr();
refParam = Replacement->isLValue();
if (refParam && Replacement->getType()->isRecordType()) {
QualType ParamType =
NTTP->isExpandedParameterPack()
? NTTP->getExpansionType(*SemaRef.ArgPackSubstIndex)
: NTTP->getType();
if (const auto *PET = dyn_cast<PackExpansionType>(ParamType))
ParamType = PET->getPattern();
refParam = ParamType->isReferenceType();
}
} else {
ExprResult result =
SemaRef.BuildExpressionFromNonTypeTemplateArgument(Arg, Loc);
if (result.isInvalid())
return ExprError();
Replacement = result.get();
refParam = Arg.getNonTypeTemplateArgumentType()->isReferenceType();
}
return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
Replacement->getType(), Replacement->getValueKind(), Loc, Replacement,
AssociatedDecl, NTTP->getIndex(), PackIndex, refParam, Final);
}

bool Sema::DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
NamedDecl *Instantiation,
bool InstantiatedFromMember,
Expand Down
Loading