[PATCH] D157376: [clang-tidy] Ignore unevaluated context in cppcoreguidelines-pro-type-vararg

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 10 13:12:38 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f29f14d0257: [clang-tidy] Ignore unevaluated context in cppcoreguidelines-pro-type-vararg (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157376/new/

https://reviews.llvm.org/D157376

Files:
  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


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
@@ -66,3 +66,16 @@
   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));
+}
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-vararg.rst
@@ -7,7 +7,8 @@
 ``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
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
   <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`.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ 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 @@
 
   Finder->addMatcher(
       callExpr(callee(functionDecl(isVariadic(),
-                                   unless(hasAnyName(AllowedVariadics)))))
+                                   unless(hasAnyName(AllowedVariadics)))),
+               unless(hasAncestor(expr(matchers::hasUnevaluatedContext()))),
+               unless(hasAncestor(typeLoc())))
           .bind("callvararg"),
       this);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157376.549147.patch
Type: text/x-patch
Size: 3170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230810/03bc5c1c/attachment-0001.bin>


More information about the cfe-commits mailing list