Skip to content

Commit 328b941

Browse files
committed
Fix Bugzilla Issue 21622 - Ambiguous template instantiation without parens crashes compiler
This fixes a compiler crash/silent failure when an ambiguous template instantiation (e.g., foo!0) matches multiple overloads exactly but is not called with parentheses. Logic added to sideeffect.d to handle EXP.scope_ resolution.
1 parent 9e57074 commit 328b941

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

compiler/src/dmd/sideeffect.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
module dmd.sideeffect;
1313

14+
import dmd.dtemplate;
15+
import dmd.dsymbol;
1416
import dmd.astenums;
1517
import dmd.declaration;
1618
import dmd.dscope;
@@ -391,6 +393,25 @@ bool discardValue(Expression e)
391393
}
392394
}
393395
return !seenSideEffect;
396+
case EXP.scope_:
397+
{
398+
if (auto se = e.isScopeExp())
399+
{
400+
if (auto ti = se.sds.isTemplateInstance())
401+
{
402+
if (!ti.aliasdecl && ti.tempdecl)
403+
{
404+
error(e.loc, "`%s` matches multiple overloads exactly", se.sds.toChars());
405+
}
406+
}
407+
else if (se.sds && se.sds.isOverloadSet())
408+
{
409+
error(e.loc, "`%s` matches multiple overloads exactly", se.sds.toChars());
410+
}
411+
}
412+
error(e.loc, "`%s` has no effect", e.toErrMsg());
413+
return true;
414+
}
394415
default:
395416
break;
396417
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
issue21622.d(17): Error: `foo!0` matches multiple overloads exactly
5+
issue21622.d(17): Error: `foo!0` has no effect
6+
---
7+
*/
8+
9+
// https://issues.dlang.org/show_bug.cgi?id=21622
10+
11+
template foo(int N) {
12+
void foo() {}
13+
}
14+
15+
void foo(int N)() {}
16+
17+
void main() {
18+
foo!0;
19+
}

0 commit comments

Comments
 (0)