[clang] [analyzer][NFC] Reorg and add clang::suppress tests (PR #186447)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 07:31:21 PDT 2026


================
@@ -0,0 +1,132 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+// Systematic tests for [[clang::suppress]] on template methods inside
+// non-template and template classes.
+
+// Placeholder types for triggering instantiations.
+// - Type{A,B} should match an unconstrained template type parameter.
+struct TypeA{};
+struct TypeB{};
+
+// ============================================================================
+// Group A: Non-template class with suppressed/unsuppressed template methods
+// ============================================================================
+
+struct NonTemplateClassWithTemplatedMethod {
+  template <typename T>
+  [[clang::suppress]] void suppressed(T) {
+    clang_analyzer_warnIfReached(); // no-warning
+  }
+
+  template <typename T>
+  void unsuppressed(T) {
+    clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+};
+
+void test_nontpl_class() {
+  NonTemplateClassWithTemplatedMethod().suppressed(TypeA{});
+  NonTemplateClassWithTemplatedMethod().unsuppressed(TypeA{});
+}
+
+// ============================================================================
+// Group B: Template class with template methods — inline
+// ============================================================================
+
+template <typename T>
+struct TemplateClassWithTemplateMethod {
+  template <typename U>
+  [[clang::suppress]] void suppressed(U) {
+    clang_analyzer_warnIfReached(); // no-warning
+  }
+
+  template <typename U>
+  void unsuppressed(U) {
+    clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+
+  template <typename U>
+  [[clang::suppress]] void suppress_at_decl_outline(U);
+
+  template <typename U>
+  void suppress_at_def_outline(U);
+};
+
+// ============================================================================
+// Group C: Template class with template methods — out-of-line
+// ============================================================================
+
----------------
NagyDonat wrote:

This separator should be removed, because the blocks above and below it depend on each other and deal with the same type `TemplateClassWithTemplateMethod`. Alternatively, you could keep them as separate groups if you eliminate the dependencies (one class with the two inline methods, one with the out-of-line ones).

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


More information about the cfe-commits mailing list