[PATCH] D142123: [clang-tidy] Add header guard style to suggest use of #pragma once

Kyle Edwards via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 3 08:03:30 PST 2023


KyleFromKitware added inline comments.


================
Comment at: clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp:569-571
+            runPragmaOnceCheck("#ifndef BOTH_H\n"
+                               "#define BOTH_H\n"
+                               "#pragma once\n"
----------------
aaron.ballman wrote:
> How about a test for:
> ```
> #if !defined(HEADER_GUARD_H)
> #define HEADER_GUARD_H 1
> 
> #endif
> ```
> and a test for what happens when there's no header guard or pragma once in the file.
> How about a test for:
> ```
> #if !defined(HEADER_GUARD_H)
> #define HEADER_GUARD_H 1
> 
> #endif
> ```

Good catch. The case of `!defined()` was not being handled by the existing header guard check except to basically ignore it. The `#pragma once` check crashed on this case. I've updated it to also ignore the `!defined()` case.

> and a test for what happens when there's no header guard or pragma once in the file.

I already have this, see the "neither" test at the bottom.


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

https://reviews.llvm.org/D142123



More information about the cfe-commits mailing list