Skip to content

Strip PCH forced-include flags when clang-tidy analyses header files#7260

Closed
Goober5000 wants to merge 1 commit intoscp-fs2open:masterfrom
Goober5000:clang_tidy_pch
Closed

Strip PCH forced-include flags when clang-tidy analyses header files#7260
Goober5000 wants to merge 1 commit intoscp-fs2open:masterfrom
Goober5000:clang_tidy_pch

Conversation

@Goober5000
Copy link
Contributor

When a header in the PCH include chain is analysed as the main source file, the -include flag causes it to be parsed twice in the same translation unit. #pragma once cannot prevent this for the main file, resulting in redefinition errors. Use a sanitized compile_commands.json (with -include/-include-pch removed) for header files only.

Claude's solution to the clang-tidy redefinition errors in #7258 as well as a few previous PRs over the years.

When a header in the PCH include chain is analysed as the main source file, the `-include` flag causes it to be parsed twice in the same translation unit.  `#pragma once` cannot prevent this for the main file, resulting in redefinition errors.  Use a sanitized compile_commands.json (with `-include`/`-include-pch` removed) for header files only.

Claude's solution to the clang-tidy redefinition errors in scp-fs2open#7258 as well as a few previous PRs over the years.
@Goober5000 Goober5000 added fix A fix for bugs, not-a-bugs, and/or regressions. build An issue related to the build systems labels Mar 3, 2026
@Goober5000 Goober5000 marked this pull request as draft March 3, 2026 02:12
@Goober5000
Copy link
Contributor Author

After further analysis, this won't actually work, since stripping the PCH information also removes header files needed to compile.

@Goober5000 Goober5000 closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build An issue related to the build systems fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant