[clang-tools-extra] [llvm] [clang-tidy] New check `misc-header-guard` (PR #177315)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 23:53:14 PDT 2026


================
@@ -0,0 +1,252 @@
+#include "header-guard/include/correct.hpp"
+#include "header-guard/include/missing.hpp"
+#include "header-guard/include/wrong.hpp"
+
+#include "header-guard/include/other/correct.hpp"
+#include "header-guard/include/other/missing.hpp"
+#include "header-guard/include/other/wrong.hpp"
+
+// ---------------------------------------
+// TEST 1: Use no config options (default)
+// ---------------------------------------
+// RUN: %check_clang_tidy %s misc-header-guard %t -export-fixes=%t.1.yaml --header-filter=.* -- -I%S > %t.1.msg 2>&1
+// RUN: FileCheck -input-file=%t.1.msg -check-prefix=CHECK-MESSAGES1 %s
+// RUN: FileCheck -input-file=%t.1.yaml -check-prefix=CHECK-YAML1 %s
+
+// CHECK-MESSAGES1: missing.hpp:1:1: warning: header is missing header guard [misc-header-guard]
+// CHECK-MESSAGES1: missing.hpp:1:1: warning: header is missing header guard [misc-header-guard]
+// CHECK-MESSAGES1: wrong.hpp:1:9: warning: header guard does not follow preferred style [misc-header-guard]
+// CHECK-MESSAGES1: wrong.hpp:1:9: warning: header guard does not follow preferred style [misc-header-guard]
+
+// CHECK-YAML1: Message:         header is missing header guard
+// CHECK-YAML1: FilePath:        '{{.*header-guard.include.}}missing.hpp'
+// CHECK-YAML1: ReplacementText: "#ifndef MISSING_HPP\n#define MISSING_HPP\n\n"
----------------
vbvictor wrote:

We now can check-messages and check-fixes directly on headers with `-check-header`: https://github.com/llvm/llvm-project/pull/175735.
Maybe we don't need yaml anymore?

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


More information about the cfe-commits mailing list