[clang-tools-extra] [clang-tidy] Fix false positive in bugprone-dynamic-static-initializers (PR #174275)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 3 07:01:42 PST 2026


================
@@ -18,12 +18,11 @@ namespace clang::tidy::bugprone {
 namespace {
 
 AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
+  if (Node.isConstexpr())
+    return true;
----------------
zeyi2 wrote:

[[dcl.constexpr]](https://eel.is/c++draft/dcl.constexpr): "A constexpr variable shall be constant-initializable", so I think it is safe to early return it and would not introduce FPs/FNs. (If a variable is marked `constexpr` but fails to be constant-initializable, the code is ill-formed and compilation will fail, so clang will report error.)

https://github.com/llvm/llvm-project/pull/174275


More information about the cfe-commits mailing list