compilerplugins/clang/compat.hxx | 13 ++++++++ compilerplugins/clang/external.cxx | 3 + compilerplugins/clang/implicitboolconversion.cxx | 37 +++++++++++++---------- compilerplugins/clang/redundantfcast.cxx | 9 +++-- compilerplugins/clang/referencecasting.cxx | 5 +-- 5 files changed, 44 insertions(+), 23 deletions(-)
New commits: commit 5baeba69bf448a60068d3bbbcf88dbdf491e41ea Author: Stephan Bergmann <[email protected]> AuthorDate: Wed Oct 26 08:54:49 2022 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Wed Oct 26 15:06:18 2022 +0200 Adapt compilerplugins to recent Clang 16 trunk change <https://github.com/llvm/llvm-project/commit/1acffe81ee9117691812b9bf8747c03354177d15> "NFC: [clang] Template argument cleanups." Change-Id: I84bc276c21efcc11643ae7003e0fee6c7592130f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141860 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index b5941c52fced..60888c15b1c9 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -162,6 +162,19 @@ inline clang::TemplateTypeParmDecl const * getReplacedParameter( #endif } +// Printing `std::size_t n` via `report(...) << n` is ambiguous prior to +// <https://github.com/llvm/llvm-project/commit/afdac5fbcb6a375245d435e4427086a376de59ff> "[clang] +// Allow printing 64 bit ints in diagnostics" (in Clang 14.x) and its follow-up +// <https://github.com/llvm/llvm-project/commit/ac7a9ef0ae3a5c63dc4e641f9912d8b659ebd720> "Resolve +// overload ambiguity on Mac OS when printing size_t in diagnostics" (in Clang 15.x): +inline +#if CLANG_VERSION >= 150000 +std::size_t +#else +unsigned +#endif +diagnosticSize(std::size_t n) { return n; } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/external.cxx b/compilerplugins/clang/external.cxx index e3bc67f19c46..de2b51ff82bc 100644 --- a/compilerplugins/clang/external.cxx +++ b/compilerplugins/clang/external.cxx @@ -77,7 +77,8 @@ bool mentions(QualType type1, QualType type2) } if (auto const t2 = t1->getAs<TemplateSpecializationType>()) { - for (auto a = t2->begin(); a != t2->end(); ++a) + auto const args = t2->template_arguments(); + for (auto a = args.begin(); a != args.end(); ++a) { if (a->getKind() != TemplateArgument::Type) { diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index b6ab52ea5798..cdf1d762cb5b 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -67,10 +67,11 @@ QualType reconstructTemplateArgumentType( if (i == ps->end()) { return {}; } - if (ps->size() != specializationType->getNumArgs()) { //TODO + auto const args = specializationType->template_arguments(); + if (ps->size() != args.size()) { //TODO return {}; } - TemplateArgument const & arg = specializationType->getArg(i - ps->begin()); + TemplateArgument const & arg = args[i - ps->begin()]; if (arg.getKind() != TemplateArgument::Type) { return {}; } @@ -183,16 +184,17 @@ bool isBoolExpr(Expr const * expr) { break; } auto const dc = loplugin::DeclCheck(d->getTemplatedDecl()); - if (dc.ClassOrStruct("array").StdNamespace() && t->getNumArgs() >= 2 - && t->getArg(0).getKind() == TemplateArgument::Type) + auto const args = t->template_arguments(); + if (dc.ClassOrStruct("array").StdNamespace() && args.size() >= 2 + && args[0].getKind() == TemplateArgument::Type) { - ty = t->getArg(0).getAsType(); + ty = args[0].getAsType(); } else if (dc.Class("Sequence").Namespace("uno").Namespace("star").Namespace("sun") .Namespace("com").GlobalNamespace() - && t->getNumArgs() == 1 - && t->getArg(0).getKind() == TemplateArgument::Type) + && args.size() == 1 + && args[0].getKind() == TemplateArgument::Type) { - ty = t->getArg(0).getAsType(); + ty = args[0].getAsType(); } else { break; } @@ -412,9 +414,10 @@ bool ImplicitBoolConversion::TraverseCXXMemberCallExpr(CXXMemberCallExpr * expr) = ct->getTemplateName().getAsTemplateDecl(); if (td != nullptr) { //TODO: fix this superficial nonsense check: - if (ct->getNumArgs() >= 1 - && ct->getArg(0).getKind() == TemplateArgument::Type - && (loplugin::TypeCheck(ct->getArg(0).getAsType()) + auto const args = ct->template_arguments(); + if (args.size() >= 1 + && args[0].getKind() == TemplateArgument::Type + && (loplugin::TypeCheck(args[0].getAsType()) .AnyBoolean())) { continue; @@ -846,9 +849,10 @@ void ImplicitBoolConversion::checkCXXConstructExpr( ps->begin(), ps->end(), compat::getReplacedParameter(t2)); if (k != ps->end()) { - if (ps->size() == t1->getNumArgs()) { //TODO - TemplateArgument const & arg = t1->getArg( - k - ps->begin()); + auto const args = t1->template_arguments(); + if (ps->size() == args.size()) { //TODO + TemplateArgument const & arg = args[ + k - ps->begin()]; if (arg.getKind() == TemplateArgument::Type && (loplugin::TypeCheck(arg.getAsType()) .AnyBoolean())) @@ -870,8 +874,9 @@ void ImplicitBoolConversion::reportWarning(ImplicitCastExpr const * expr) { if (expr->getCastKind() == CK_ConstructorConversion) { auto const t1 = expr->getType(); if (auto const t2 = t1->getAs<TemplateSpecializationType>()) { - assert(t2->getNumArgs() >= 1); - auto const a = t2->getArg(0); + auto const args = t2->template_arguments(); + assert(args.size() >= 1); + auto const a = args[0]; if (a.getKind() == TemplateArgument::Type && a.getAsType()->isBooleanType() && (loplugin::TypeCheck(t1).TemplateSpecializationClass() .ClassOrStruct("atomic").StdNamespace())) diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx index 38a7daf9fff7..5e74b22fe937 100644 --- a/compilerplugins/clang/redundantfcast.cxx +++ b/compilerplugins/clang/redundantfcast.cxx @@ -230,18 +230,19 @@ public: { return false; } - if (t2->getNumArgs() != 1) + auto const args = t2->template_arguments(); + if (args.size() != 1) { if (isDebugMode()) { report(DiagnosticsEngine::Fatal, "TODO: unexpected std::function with %0 template arguments", expr->getExprLoc()) - << t2->getNumArgs() << expr->getSourceRange(); + << compat::diagnosticSize(args.size()) << expr->getSourceRange(); } return false; } - if (t2->getArg(0).getKind() != TemplateArgument::Type) + if (args[0].getKind() != TemplateArgument::Type) { if (isDebugMode()) { @@ -252,7 +253,7 @@ public: } return false; } - target = t2->getArg(0).getAsType(); + target = args[0].getAsType(); } else { diff --git a/compilerplugins/clang/referencecasting.cxx b/compilerplugins/clang/referencecasting.cxx index 2cc4a627bba9..cff5b050ea9f 100644 --- a/compilerplugins/clang/referencecasting.cxx +++ b/compilerplugins/clang/referencecasting.cxx @@ -518,9 +518,10 @@ static const RecordType* extractTemplateType(QualType cceType) auto cceTST = dyn_cast<TemplateSpecializationType>(cceType); if (!cceTST) return NULL; - if (cceTST->getNumArgs() != 1) + auto const args = cceTST->template_arguments(); + if (args.size() != 1) return NULL; - const TemplateArgument& cceTA = cceTST->getArg(0); + const TemplateArgument& cceTA = args[0]; QualType templateParamType = cceTA.getAsType(); if (auto elaboratedType = dyn_cast<ElaboratedType>(templateParamType)) templateParamType = elaboratedType->desugar();
