diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp index c87b3ea7e261..00e8f7e51436 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp @@ -9,7 +9,6 @@ #include "ForwardingReferenceOverloadCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" -#include using namespace clang::ast_matchers; @@ -19,14 +18,14 @@ namespace { // Check if the given type is related to std::enable_if. AST_MATCHER(QualType, isEnableIf) { auto CheckTemplate = [](const TemplateSpecializationType *Spec) { - if (!Spec || !Spec->getTemplateName().getAsTemplateDecl()) { + if (!Spec) return false; - } - const NamedDecl *TypeDecl = - Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl(); - return TypeDecl->isInStdNamespace() && - (TypeDecl->getName() == "enable_if" || - TypeDecl->getName() == "enable_if_t"); + + const TemplateDecl *TDecl = Spec->getTemplateName().getAsTemplateDecl(); + + return TDecl && TDecl->isInStdNamespace() && + (TDecl->getName() == "enable_if" || + TDecl->getName() == "enable_if_t"); }; const Type *BaseType = Node.getTypePtr(); // Case: pointer or reference to enable_if. diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 8d0c093b312d..465c333efdf3 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -111,6 +111,10 @@ Changes in existing checks ` check to suggest replacing the offending code with ``reinterpret_cast``, to more clearly express intent. +- Improved :doc:`bugprone-forwarding-reference-overload + ` check by fixing + a crash when determining if an ``enable_if[_t]`` was found. + - Improved :doc:`cert-flp30-c` check to fix false positive that floating point variable is only used in increment expression. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp index 92dfb718bb51..27315199c7eb 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp @@ -261,3 +261,9 @@ public: Test11(const Test11 &) = default; Test11(Test11 &&) = default; }; + +template