Skip to content

MISRA C:2025: DIR-4-10 report include guards reused across header files - #1230

Draft
mbaluda wants to merge 2 commits into
misra-c-2025-developmentfrom
mbaluda/dir-4-10-unique-guards
Draft

mbaluda wants to merge 2 commits into
misra-c-2025-developmentfrom
mbaluda/dir-4-10-unique-guards

Conversation

@mbaluda

@mbaluda mbaluda commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

MISRA C:2025 changes Dir 4.10 so that the uniqueness requirement for include-guard names is now normative.

This PR updates the shared IncludeGuardsNotUsed check so that it reports header files that share an include-guard name, even when the headers have different extensions or are included only from separate translation units.

The new check applies to every MISRA C edition, because MISRA C:2012 already had the same intent.

Affected queries

All queries using the shared IncludeGuardsNotUsed library can now report new results:

  • c/misra/precaution-include-guards-not-provided (MISRA C Dir 4.10)
  • cpp/autosar/include-guards-not-provided (AUTOSAR M16-2-3)
  • cpp/misra/no-valid-ifdef-guard-in-header (MISRA C++:2023 Rule 19.2.1)

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • rule number here
  • Queries have been modified for the following rules:
    • DIR-4-10
    • M16-2-3
    • RULE-19-2-1

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

Query development review checklist

For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:

Author

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development November 26, 2026 14:42
@mbaluda

mbaluda commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

/test-performance

@github-actions

This comment was marked as resolved.

@codeql-coding-standards-automation

This comment was marked as resolved.

@mbaluda
mbaluda marked this pull request as ready for review December 2, 2026 10:58
@mbaluda
mbaluda requested review from a team and an adaptive review from Copilot December 2, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The duplicate-guard lookup misses the first header when the other is blocked in their only translation unit, requiring broader lookup coverage and a regression assertion.

1 open issue
What changed in this PR

Extends the shared include-guard check to report reused guard names across header extensions and translation units, affecting MISRA C, MISRA C++, and AUTOSAR queries.

Changes:

  • Adds duplicate-guard detection and linked diagnostic messages.
  • Adds cross-translation-unit fixtures and expected results.
  • Documents the expanded query results in a change note.
File Description
cpp/​common/​test/​rules/​includeguardsnotused/​test2.cpp Includes the duplicate guard in a separate translation unit.
cpp/​common/​test/​rules/​includeguardsnotused/​test.cpp Includes the first duplicate-guard header.
cpp/​common/​test/​rules/​includeguardsnotused/​IncludeGuardsNotUsed.expected Adds expected duplicate-guard alerts.
cpp/​common/​test/​rules/​includeguardsnotused/​headers/​dir410_b.hpp Adds the second shared-guard fixture.
cpp/​common/​test/​rules/​includeguardsnotused/​headers/​dir410_a.h Adds the first shared-guard fixture.
cpp/​common/​src/​codingstandards/​cpp/​rules/​includeguardsnotused/​IncludeGuardsNotUsed.qll Detects and reports reused guard names.
change_notes/​2026-10-19-expand-dir-4-10.md Records the affected queries and expanded behavior.

Review effort: Balanced (adaptive)

@mbaluda mbaluda changed the title DIR-4-10: Report include guards reused across header files MISRA C:2025: DIR-4-10 report include guards reused across header files Dec 2, 2026
@mbaluda
mbaluda force-pushed the misra-c-2025-development branch from 3a2fdff to 0ba605d Compare December 3, 2026 14:47
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main December 4, 2026 12:07
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development December 4, 2026 12:10
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main December 4, 2026 12:30
@mbaluda
mbaluda marked this pull request as draft December 4, 2026 12:36
@mbaluda mbaluda closed this Dec 4, 2026
@mbaluda mbaluda reopened this Dec 4, 2026
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development December 4, 2026 12:55
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mbaluda
mbaluda force-pushed the mbaluda/dir-4-10-unique-guards branch from b025d4c to 768e3d5 Compare December 4, 2026 12:59
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main December 4, 2026 13:00
@mbaluda mbaluda closed this Dec 4, 2026
@mbaluda mbaluda reopened this Dec 4, 2026
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development December 4, 2026 13:01
@mbaluda
mbaluda changed the base branch from misra-c-2025-development to main December 4, 2026 17:16
@mbaluda mbaluda closed this Dec 4, 2026
@mbaluda mbaluda reopened this Dec 4, 2026
@mbaluda
mbaluda changed the base branch from main to misra-c-2025-development December 4, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants