diff --git a/compiler/src/dmd/cparse.d b/compiler/src/dmd/cparse.d index 6c78e944a5..2c5a4f0e76 100644 --- a/compiler/src/dmd/cparse.d +++ b/compiler/src/dmd/cparse.d @@ -1886,15 +1886,6 @@ final class CParser(AST) : Parser!AST } if (s !is null) { - s = applySpecifier(s, specifier); - if (level == LVL.local) - { - // Wrap the declaration in `extern (C) { declaration }` - // Necessary for function pointers, but harmless to apply to all. - auto decls = new AST.Dsymbols(1); - (*decls)[0] = s; - s = new AST.LinkDeclaration(s.loc, linkage, decls); - } // Saw `asm("name")` in the function, type, or variable definition. // This is equivalent to `pragma(mangle, "name")` in D if (asmName) @@ -1917,6 +1908,15 @@ final class CParser(AST) : Parser!AST p.mangleOverride = str; } } + s = applySpecifier(s, specifier); + if (level == LVL.local) + { + // Wrap the declaration in `extern (C) { declaration }` + // Necessary for function pointers, but harmless to apply to all. + auto decls = new AST.Dsymbols(1); + (*decls)[0] = s; + s = new AST.LinkDeclaration(s.loc, linkage, decls); + } symbols.push(s); } first = false; diff --git a/compiler/test/runnable/test23347.c b/compiler/test/runnable/test23347.c new file mode 100644 index 0000000000..d213a2b225 --- /dev/null +++ b/compiler/test/runnable/test23347.c @@ -0,0 +1,19 @@ +/* DISABLED: osx32 osx64 win32 win64 + * TEST_OUTPUT: +--- +--- + */ + +// https://issues.dlang.org/show_bug.cgi?id=23347 + +void fork() { } + +#pragma pack(push, 4) +void spoon() asm("fork"); +#pragma pack(pop); + +int main() +{ + spoon(); + return 0; +}