diff --git a/source/dpp/translation/macro_.d b/source/dpp/translation/macro_.d index c4d9e8f6..bf7640cd 100644 --- a/source/dpp/translation/macro_.d +++ b/source/dpp/translation/macro_.d @@ -434,7 +434,14 @@ private auto fixCasts(R)( && tokens[scanIndex].spelling[0] == '.' ; - if(isType(tokens[i + 1 .. scanIndex - 1]) && !followedByDot) { + // make sure this is not a function call (look before the open paren) + const isFunctionParam = + i > 0 + && tokens[i - 1].kind == Token.Kind.Identifier; + + if(isType(tokens[i + 1 .. scanIndex - 1]) + && !followedByDot + && !isFunctionParam) { middle ~= tokens[lastIndex .. i] ~ Token(Token.Kind.Punctuation, "cast(") ~ tokens[i + 1 .. scanIndex]; // includes closing paren diff --git a/tests/it/c/compile/preprocessor.d b/tests/it/c/compile/preprocessor.d index 618003d2..d866ba95 100644 --- a/tests/it/c/compile/preprocessor.d +++ b/tests/it/c/compile/preprocessor.d @@ -130,3 +130,23 @@ version(Posix) // FIXME ) ); } + +@("macro function's parameter name is a type") +@safe unittest { + shouldCompile( + C( + ` + struct Foo {}; + void actual_func(struct Foo*); + #define func(Foo) actual_func(Foo) + ` + ), + D( + q{ + void actual_func(Foo *) {} + Foo *f; + func(f); + } + ) + ); +}