From: Michael Buch Date: Tue, 13 Dec 2022 14:30:17 +0000 (+0000) Subject: [clang][TypePrinter] Teach isSubstitutedDefaultArgument about integral types X-Git-Tag: upstream/17.0.6~23564 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1706f34d604ec304af58a7b95dbc127bd77e17fa;p=platform%2Fupstream%2Fllvm.git [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 --- 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