[libc-commits] [libc] [libc][clang-tidy] Add llvm-header-guard to get consistant naming and prevent file copy/paste issues. (PR #66477)

Siva Chandra via libc-commits libc-commits at lists.llvm.org
Wed Sep 20 07:02:58 PDT 2023


sivachandra wrote:

> > We are not uniform, but I think we should follow this:
> > `__LLVM_LIBC_<FILE_NAME_IN_UPPER_SNAKE_CASE>_H__`
> 
> `llvm-header-guard` derives from `header-guard` and [forbids header guards starting with underscores](https://github.com/llvm/llvm-project/blob/797cad9d32885ca7a0ccfa657eba5c739f189e98/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp#L282-L285) ([original bug](https://bugs.llvm.org/show_bug.cgi?id=48613)).
> 
> ```
> std::string HeaderGuardCheck::sanitizeHeaderGuard(StringRef Guard) {
>   // Only reserved identifiers are allowed to start with an '_'.
>   return Guard.drop_while([](char C) { return C == '_'; }).str();
> }
> ```
> 
> If we drop this requirement, `llvm-header-guard` can already be used as is and doesn't need to be adapted to llvm libc.

Clang's freestanding headers use a guard with `__CLANG` prefix so libc is not being special in that sense. The `__` prefix is required so that we do not pollute user namespace.

What is the goal here? Is to use clang-tidy to catch header-guard errors in `include`/`${LIBC_INCLUDE_DIR}?

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


More information about the libc-commits mailing list