[PATCH] D114149: [clang-tidy] Fix pr48613: "llvm-header-guard uses a reserved identifier"
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 18 05:24:11 PST 2021
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp:42-46
+/// Remove all '_' characters at the beginning of the identifier. Only reserved
+/// identifiers are allowed to start with these.
+static StringRef dropLeadingUnderscores(StringRef Identifier) {
+ return Identifier.drop_while([](char c) { return c == '_'; });
+}
----------------
whisperity wrote:
> Is this true? At least in C++ (and perhaps in C) I believe `_foo` is a non-reserved identifier, only `__foo` or `_Foo` would be reserved.
`_foo` is reserved if its an external identifier in both C and C++: https://godbolt.org/z/GnG4v33vK
However, the issue here is that header guards are capitalized, so a file name like `_foo` still should drop the leading underscore so it doesn't get turned into `_FOO` which is always reserved.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114149/new/
https://reviews.llvm.org/D114149
More information about the cfe-commits
mailing list