Skip to content

Fix reconstructed header dropping macros whose name/value contains the include guard (#1266) - #1272

Merged
mkarlesky merged 2 commits into
masterfrom
fix/1266-include-guard-substring-master
Sep 8, 2026
Merged

Fix reconstructed header dropping macros whose name/value contains the include guard (#1266)#1272
mkarlesky merged 2 commits into
masterfrom
fix/1266-include-guard-substring-master

Conversation

@mkarlesky

Copy link
Copy Markdown
Member

Fixes #1266. This is a port of #1271 (green on next_version) to master, for inclusion in 1.1.8.

Root cause

extract_macro_defs filtered a header's own include guard out of the reconstructed macro list with a plain substring test (macro.include?(include_guard)). That also rejected any ordinary macro whose name or value merely happened to contain the guard string as a substring — e.g. with guard RTC_H:

#define RTC_HOUR_SECONDS (60u * RTC_MINUTE_SECONDS)   // name contains "RTC_H"
#define RTC_DAY_SECONDS (24u * RTC_HOUR_SECONDS)       // value references RTC_HOUR_SECONDS, so it too contains "RTC_H"

Both were silently dropped from the reconstructed header, producing undeclared-identifier compile errors — exactly as reported.

Fix

The match is now anchored to #define <guard> followed by whitespace or end-of-line, so only the guard's own definition line matches.

Tests

Same coverage as #1271: new #extract_macro_defs cases in preprocessinator_reconstructor_spec.rb using the reporter's own RTC example, verified failing against pre-fix code, passing after. Unit tests only, no system tests. bundle exec rake specs:units clean (1991 examples, 0 failures, 1 pre-existing unrelated pending).

🤖 Generated with Claude Code

mkarlesky and others added 2 commits September 8, 2026 17:57
…e include guard

extract_macro_defs used a plain substring test (macro.include?(include_guard))
to filter out a header's own include guard from its reconstructed macro list.
That also rejected any ordinary macro whose name or value merely happened to
contain the guard string -- e.g. guard RTC_H matching inside RTC_HOUR_SECONDS'
own name, or inside RTC_DAY_SECONDS' value, which references
RTC_HOUR_SECONDS. Both were silently dropped from the reconstructed header,
producing undeclared-identifier compile errors (GH #1266).

The match is now anchored to "#define <guard>" followed by whitespace or
end-of-line, matching only the guard's own definition.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
[skip ci]

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mkarlesky
mkarlesky merged commit 3e45652 into master Sep 8, 2026
@mkarlesky
mkarlesky deleted the fix/1266-include-guard-substring-master branch September 8, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated header missing defines when macro contains include guard macro substring

1 participant