Skip to content

Prevent macro expansion in preprocessor __has_include test - #1548

Open
i-garrison wants to merge 4 commits into
eclipse-cdt:mainfrom
i-garrison:bugfix/parser-scanner-has-include-prevent-macro-expansion
Open

i-garrison wants to merge 4 commits into
eclipse-cdt:mainfrom
i-garrison:bugfix/parser-scanner-has-include-prevent-macro-expansion

Conversation

@i-garrison

@i-garrison i-garrison commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
  • prevent macro expansion for __has_include preprocessor expression
  • colorize __has_include() argument as header file, note header navigation from argument is not implemented
    fixes __has_include fails with <linux/fs.h> #1547

@eclipse-cdt-bot

Copy link
Copy Markdown

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

core/org.eclipse.cdt.core/META-INF/MANIFEST.MF

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From ca98a96204b9ac3f2f2eaa919b61b84a051f85c0 Mon Sep 17 00:00:00 2001
From: Eclipse CDT Bot <cdt-bot@eclipse.org>
Date: Fri, 30 Oct 2026 21:07:44 +0000
Subject: [PATCH] Version bump(s) for 12.7.0 stream


diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index 3f5437aac3..a5bee5b518 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
-Bundle-Version: 9.3.200.qualifier
+Bundle-Version: 9.3.300.qualifier
 Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
-- 
2.56.0

Further information are available in Common Build Issues - Missing version increments.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Test Results

4 723 tests  ±0   4 714 ✅ ±0   2m 34s ⏱️ +3s
  185 suites ±0       9 💤 ±0 
  185 files   ±0       0 ❌ ±0 

Results for commit 48e809e. ± Comparison against base commit f8b3327.

♻️ This comment has been updated with latest results.

@i-garrison
i-garrison force-pushed the bugfix/parser-scanner-has-include-prevent-macro-expansion branch from f39212b to c835132 Compare November 2, 2026 06:49
@MarkZ3

MarkZ3 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Would it have worked to use Lexer.setInsideIncludeDirective? Presumably the lack of macro expansion is already handled for normal includes.

@i-garrison

i-garrison commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Would it have worked to use Lexer.setInsideIncludeDirective? Presumably the lack of macro expansion is already handled for normal includes.

Unfortunately no atm, since Lexer.setInsideIncludeDirective works at the level where lexer is reading input tokens, and not in context with expanded macro tokens (where context lexer is null).

Guess that part of interaction between Lexer and CPreprocessor can be somehow refactored to work with with macro expansions. Then it will be able to produce more natural naturally looking quote ans system header tokens even after macro expansions. Also the part which does #if evaluation will naturally deal with just quote and system header name tokens without manually parsing lt and gt and string in between.

EDIT: added a couple of tests after looking again and this change needs to be improved as it does not allow header name via macro, will have another look now.

@i-garrison
i-garrison marked this pull request as draft November 4, 2026 07:10
@i-garrison
i-garrison force-pushed the bugfix/parser-scanner-has-include-prevent-macro-expansion branch from 2f72fa8 to 85fd7a3 Compare November 4, 2026 18:56
@i-garrison
i-garrison force-pushed the bugfix/parser-scanner-has-include-prevent-macro-expansion branch from 85fd7a3 to 48e809e Compare November 4, 2026 19:23
@i-garrison

i-garrison commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Would it have worked to use Lexer.setInsideIncludeDirective? Presumably the lack of macro expansion is already handled for normal includes.

Thanks for the hint, just made a change which actually uses Lexer.setInsideIncludeDirective. Was confused about when to prevent macro expansion. Turned out that parser will actually ask lexer for next token exactly when expansion should not be performed for __has_include, so it worked well in the end.

@i-garrison
i-garrison marked this pull request as ready for review November 4, 2026 19:31
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.

__has_include fails with <linux/fs.h>

3 participants