Skip to content

Commit 21f5ee0

Browse files
authored
[clang-tidy]fix crashing when self include cycles for misc-header-include-cycle (#94636)
Fixes: #94634
1 parent 5c0df5f commit 21f5ee0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ class CyclicDependencyCallbacks : public PPCallbacks {
139139

140140
auto CurrentIt = Files.rbegin();
141141
do {
142-
Check.diag(CurrentIt->Loc, "'%0' included from here", DiagnosticIDs::Note)
143-
<< CurrentIt->Name;
142+
if (CurrentIt->Loc.isValid())
143+
Check.diag(CurrentIt->Loc, "'%0' included from here",
144+
DiagnosticIDs::Note)
145+
<< CurrentIt->Name;
144146
} while (CurrentIt++ != It);
145147
}
146148

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ Changes in existing checks
317317
Additionally, the option `UseHeaderFileExtensions` is removed, so that the
318318
check uses the `HeaderFileExtensions` option unconditionally.
319319

320+
- Improved :doc:`misc-header-include-cycle
321+
<clang-tidy/checks/misc/header-include-cycle>` check by avoiding crash for self
322+
include cycles.
323+
320324
- Improved :doc:`misc-unused-using-decls
321325
<clang-tidy/checks/misc/unused-using-decls>` check by replacing the local
322326
option `HeaderFileExtensions` by the global option of the same name.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: not clang-tidy %s -checks='-*,misc-header-include-cycle'
2+
3+
#include "header-include-cycle.self.cpp"

0 commit comments

Comments
 (0)