Author: Piotr Zegar Date: 2023-08-10T19:51:09Z New Revision: 7f29f14d025702a04ca3e5cdd31de40c392e2799
URL: https://github.com/llvm/llvm-project/commit/7f29f14d025702a04ca3e5cdd31de40c392e2799 DIFF: https://github.com/llvm/llvm-project/commit/7f29f14d025702a04ca3e5cdd31de40c392e2799.diff LOG: [clang-tidy] Ignore unevaluated context in cppcoreguidelines-pro-type-vararg Ignore decltype, sizeof, alignof in this check. Fixes: #30542 Reviewed By: ccotter Differential Revision: https://reviews.llvm.org/D157376 Added: Modified: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp index ac1f40cfe18ae6..3923df312791db 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "ProTypeVarargCheck.h" +#include "../utils/Matchers.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" @@ -133,7 +134,9 @@ void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( callExpr(callee(functionDecl(isVariadic(), - unless(hasAnyName(AllowedVariadics))))) + unless(hasAnyName(AllowedVariadics)))), + unless(hasAncestor(expr(matchers::hasUnevaluatedContext()))), + unless(hasAncestor(typeLoc()))) .bind("callvararg"), this); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index c4b09bae18ec37..7f3ae301081231 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -176,6 +176,10 @@ Changes in existing checks <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to ignore delegate constructors. +- Improved :doc:`cppcoreguidelines-pro-type-vararg + <clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check to ignore + false-positives in unevaluated context (e.g., ``decltype``, ``sizeof``, ...). + - Improved :doc:`llvm-namespace-comment <clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for ``inline`` namespaces in the same format as :program:`clang-format`. diff --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst index 823b0eaaad382e..e74b00694630bf 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst @@ -7,7 +7,8 @@ This check flags all calls to c-style vararg functions and all use of ``va_arg``. To allow for SFINAE use of vararg functions, a call is not flagged if a literal -0 is passed as the only vararg argument. +0 is passed as the only vararg argument or function is used in unevaluated +context. Passing to varargs assumes the correct type will be read. This is fragile because it cannot generally be enforced to be safe in the language and so relies diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp index e5bf98f02d8b39..6792c7920dd112 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp @@ -66,3 +66,16 @@ void no_false_positive_desugar_va_list(char *in) { char *tmp1 = in; void *tmp2 = in; } + +namespace PR30542 { + struct X; + template <typename T> + char IsNullConstant(X*); + template <typename T> + char (&IsNullConstant(...))[2]; + + static_assert(sizeof(IsNullConstant<int>(0)) == 1, ""); + static_assert(sizeof(IsNullConstant<int>(17)) == 2, ""); + + using Type = decltype(IsNullConstant<int>(17)); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits