Skip to content

Commit

Permalink
Fix bugzilla 24431 - dmd -vcg-ast crashes printing failed template in… (
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Oct 3, 2024
1 parent e0259d9 commit 3f48f53
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -1720,10 +1720,10 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
//printf("FuncDeclaration::toCBuffer() '%s'\n", f.toChars());
if (stcToBuffer(buf, f.storage_class))
buf.writeByte(' ');
typeToBuffer(f.type, f.ident, buf, hgs);
auto tf = f.type.isTypeFunction();
typeToBuffer(tf, f.ident, buf, hgs);

if (hgs.hdrgen)
if (hgs.hdrgen && tf)
{
// if the return type is missing (e.g. ref functions or auto)
// https://issues.dlang.org/show_bug.cgi?id=20090
Expand Down
69 changes: 69 additions & 0 deletions compiler/test/compilable/vcg_ast_compilable.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
REQUIRED_ARGS: -vcg-ast -o-
OUTPUT_FILES: compilable/vcg_ast_compilable.d.cg
TEST_OUTPUT:
---
=== compilable/vcg_ast_compilable.d.cg
import object;
auto binaryFun(E)(E b)
{
return 'a' == b;
}
void find(Element)(Element needle) if (is(typeof(binaryFun(needle))))
{
}
void find()(string needle)
{
}
void splitter()
{
find(3);
find("");
}
binaryFun!int
{
auto pure nothrow @nogc @safe bool binaryFun(int b)
{
return 97 == b;
}
}
find!int
{
pure nothrow @nogc @safe void find(int needle)
{
}
}
binaryFun!string
{
auto _error_ binaryFun
{
__error__
}
}
find!()
{
pure nothrow @nogc @safe void find(string needle)
{
}
}
---
*/

// https://issues.dlang.org/show_bug.cgi?id=24431
auto binaryFun(E)(E b)
{
return 'a' == b;
}

void find(Element)(Element needle) if (is(typeof(binaryFun(needle)))) { }
void find()(string needle) { }

void splitter()
{
find!int(3);
find!()("");
}

0 comments on commit 3f48f53

Please sign in to comment.