From 1706f34d604ec304af58a7b95dbc127bd77e17fa Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 13 Dec 2022 14:30:17 +0000 Subject: [PATCH] [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types This patch handles default integral non-type template parameters. After this patch the clang TypePrinter will omit default integral template arguments when the `PrintingPolicy::SuppressDefaultTemplateArgs` option is specified and sets us up to be able to re-use `clang::isSubstitutedDefaultArgument` from the DWARF CodeGen component. Differential Revision: https://reviews.llvm.org/D139986 --- clang/lib/AST/TypePrinter.cpp | 10 ++++++++++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp | 2 +- clang/test/CodeGenObjCXX/encode.mm | 7 +++++-- clang/test/Misc/diag-template-diffing.cpp | 4 ++-- clang/test/Misc/diag-template.cpp | 2 +- clang/test/SemaCUDA/device-use-host-var.cu | 2 +- clang/test/SemaCXX/co_await-range-for-exp-namespace.cpp | 2 +- clang/test/SemaCXX/co_await-range-for.cpp | 2 +- clang/test/SemaCXX/coroutines-exp-namespace.cpp | 2 +- clang/test/SemaCXX/coroutines.cpp | 2 +- clang/test/SemaCXX/cxx11-call-to-deleted-constructor.cpp | 2 +- clang/test/SemaTemplate/deduction-guide.cpp | 2 +- clang/test/SemaTemplate/dependent-names.cpp | 2 +- 13 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index bfab41b..5c24649 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2025,6 +2025,16 @@ static bool isSubstitutedTemplateArgument(ASTContext &Ctx, TemplateArgument Arg, } } + if (Arg.getKind() == TemplateArgument::Integral && + Pattern.getKind() == TemplateArgument::Expression) { + Expr const *expr = Pattern.getAsExpr(); + + if (!expr->isValueDependent() && expr->isIntegerConstantExpr(Ctx)) { + return llvm::APSInt::isSameValue(expr->EvaluateKnownConstInt(Ctx), + Arg.getAsIntegral()); + } + } + if (Arg.getKind() != Pattern.getKind()) return false; diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp index 0c555b5..51489c5 100644 --- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp +++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp @@ -15,7 +15,7 @@ eval> eA; eval> eB; eval> eC; // expected-error{{implicit instantiation of undefined template 'eval>'}} eval> eD; // expected-error{{implicit instantiation of undefined template 'eval>'}} -eval> eE; // expected-error{{implicit instantiation of undefined template 'eval>}} +eval> eE; // expected-error{{implicit instantiation of undefined template 'eval>}} template