From 4a64ef41b0e6ff097ed43b1ecbe4578bac1ceaec Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Wed, 12 Apr 2023 15:43:22 +0300 Subject: [PATCH] Fix Issue 22765 - Assertion failure in CppMangleVisitor.template_args --- compiler/src/dmd/cppmangle.d | 6 +++++- compiler/test/fail_compilation/test22765.d | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 compiler/test/fail_compilation/test22765.d diff --git a/compiler/src/dmd/cppmangle.d b/compiler/src/dmd/cppmangle.d index b015a642b909..0319eef04126 100644 --- a/compiler/src/dmd/cppmangle.d +++ b/compiler/src/dmd/cppmangle.d @@ -560,7 +560,11 @@ private final class CppMangleVisitor : Visitor foreach (j; i .. (*ti.tiargs).length) { Type t = isType((*ti.tiargs)[j]); - assert(t); + if (t is null) + { + ti.error("internal compiler error: C++ `%s` template value parameter is not supported", (*ti.tiargs)[j].toChars()); + fatal(); + } t.accept(this); } diff --git a/compiler/test/fail_compilation/test22765.d b/compiler/test/fail_compilation/test22765.d new file mode 100644 index 000000000000..0d1b582d5176 --- /dev/null +++ b/compiler/test/fail_compilation/test22765.d @@ -0,0 +1,14 @@ +// https://issues.dlang.org/show_bug.cgi?id=22765 + +/* +TEST_OUTPUT: +--- +fail_compilation/test22765.d(14): Error: template instance `test22765.Template!null` internal compiler error: C++ `null` template value parameter is not supported +--- +*/ + +template Template(T...) +{ + extern(C++) const __gshared int Template = 0; +} +auto x = Template!(null);