Skip to content
6 changes: 6 additions & 0 deletions compiler/src/dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ final class CParser(AST) : Parser!AST
const id = token.ident.toString();
if (id.length > 2 && id[0] == '_' && id[1] == '_') // leading double underscore
{
if (token.ident is Id.FUNCTION || token.ident is Id.PRETTY_FUNCTION) //__FUNCTION__ predefined macro
{
e = new AST.FuncInitExp(loc);
nextToken();
break;
}
if (token.ident is Id.__func__)
{
addFuncName = true; // implicitly declare __func__
Expand Down
12 changes: 12 additions & 0 deletions compiler/test/compilable/func.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <assert.h>
#include <string.h>
void foo()
{
assert(strcmp(__FUNCTION__, "foo") == 0);
assert(strcmp(__PRETTY_FUNCTION__, "func.foo") == 0);
}

int main()
{
foo();
}
Loading