llvm / llvm/llvm-project

[clang-tidy] [With reproducible example] Erroneous rule "llvm-header-guard" since v21.0.0

Open
#164,417 6 comments 1 reaction 0 assignees View on GitHub
clang-tidy confirmed regression:21
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

All my header guards raise issues now which never was the case before. The following example file is called `constant.hpp`. See the warning in line 2.

```c++
#ifndef CONSTANT_HPP
#define CONSTANT_HPP //code/includes outside of area guarded by header guard; consider moving it [llvm-header-guard]

#include

namespace constant
{
//Variables
/**
* @var name
* @brief Programme name.
*/
extern const std::string name;
/**
* @var release
* @brief Release date of the version.
*/
extern const std::string release;
/**
* @var version
* @brief Version.
*/
extern const std::string version;

//Functions
/**
* @brief Creates the programme name in lower case.
* @return Programme name in lower case.
*/
std::string name_lower_case();
} //namespace constant

#endif
```

Contributor guide

Open the contributing guide

Research direction

Start with the clang-tidy `llvm-header-guard` rule and reproduce the warning using the provided `constant.hpp` example, especially the `#define CONSTANT_HPP` line. Trace why this valid guard is treated as code outside the guarded area; done means the example no longer produces the erroneous warning and the behavior is covered by the rule's tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.