Skip to content

Commit f2fcacb

Browse files
authored
ImportC: Add test for function-like macro calling another macro (#22349)
* ImportC: Add test for function-like macro calling another macro Tests the `if (params) break;` branch in TOK.identifier case, ensuring function-like macros with identifier bodies are handled by caseFunctionLike, not the new nullary template path. * ImportC: Replace unreachable branch with assertion When we reach TOK.identifier case, params is always false because if params were true (macro name followed by '('), the next token would be TOK.leftParenthesis, not TOK.identifier.
1 parent 795e381 commit f2fcacb

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

compiler/src/dmd/cparse.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5779,8 +5779,7 @@ final class CParser(AST) : Parser!AST
57795779
* Rewrite to a template function:
57805780
* auto ID()() { return identifier(args); }
57815781
*/
5782-
if (params)
5783-
break; // function-like macro with params handled elsewhere
5782+
assert(!params); // would be TOK.leftParenthesis
57845783
eLatch.sawErrors = false;
57855784
auto exp = cparseExpression();
57865785
if (eLatch.sawErrors) // parsing errors

compiler/test/compilable/imports/defines.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ int pr16199c()
6868
#define DOUBLE(x) ((x) * 2)
6969
#define BARE_CALL DOUBLE(5) // bare function-like macro call (no outer parens)
7070
#define PAREN_CALL (DOUBLE(5)) // parenthesized call (already works)
71+
#define WRAPPER(x) DOUBLE(x) // function-like macro calling another macro

compiler/test/compilable/testdefines.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ static assert(is(typeof(NEGATIVE_F64) == double));
4444
static assert(DOUBLE(5) == 10);
4545
static assert(BARE_CALL == 10); // bare call now works
4646
static assert(PAREN_CALL == 10); // parenthesized already worked
47+
static assert(WRAPPER(3) == 6); // function-like macro calling another macro

0 commit comments

Comments
 (0)