From 8b0bdc3d237dd4b9ab41290509546cd225a93f2c Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 31 Aug 2024 15:20:35 +0200 Subject: [PATCH 1/2] Fix bugzilla 24731 - IFTI cannot handle integer expressions (dlang/dmd!16822) --- dmd/dtemplate.d | 4 +++- dmd/expression.d | 2 +- tests/dmd/runnable/ifti.d | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/dmd/dtemplate.d b/dmd/dtemplate.d index 19de63db669..dfb18a8ed5d 100644 --- a/dmd/dtemplate.d +++ b/dmd/dtemplate.d @@ -1698,7 +1698,9 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, ref TemplateParameters pa edim = s ? getValue(s) : getValue(e); } } - if (tp && tp.matchArg(sc, t.dim, i, ¶meters, dedtypes, null) || edim && edim.toInteger() == t.dim.toInteger()) + if ((tp && tp.matchArg(sc, t.dim, i, ¶meters, dedtypes, null)) || + (edim && edim.isIntegerExp() && edim.toInteger() == t.dim.toInteger()) + ) { result = deduceType(t.next, sc, tparam.nextOf(), parameters, dedtypes, wm); return; diff --git a/dmd/expression.d b/dmd/expression.d index b5fb0e2b9b3..018a73d70a3 100644 --- a/dmd/expression.d +++ b/dmd/expression.d @@ -474,7 +474,7 @@ extern (C++) abstract class Expression : ASTNode dinteger_t toInteger() { //printf("Expression %s\n", EXPtoString(op).ptr); - if (!type.isTypeError()) + if (!type || !type.isTypeError()) error(loc, "integer constant expression expected instead of `%s`", toChars()); return 0; } diff --git a/tests/dmd/runnable/ifti.d b/tests/dmd/runnable/ifti.d index 0c94946c8b3..293b8198d7f 100644 --- a/tests/dmd/runnable/ifti.d +++ b/tests/dmd/runnable/ifti.d @@ -72,6 +72,20 @@ class Tst(TST, int v = 2) { class Y : Tst!(float) {} +// https://issues.dlang.org/show_bug.cgi?id=24731 +void test24731() +{ + static int solve(size_t N)(ref double[N+1][N]) + { + return N; + } + + double[3][2] m; + assert(solve(m) == 2); + assert(solve!2(m) == 2); +} + + void main() { Tst!(int) t = new Tst!(int); Y u = new Y; @@ -113,4 +127,5 @@ void main() { printf("%g\n", i); } + test24731(); } From 9ce0aab56bb73cb38ff4156b5cd3e024214a9d2e Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 8 Sep 2024 16:32:40 +0200 Subject: [PATCH 2/2] [extend changelog entry] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efc797b87b7..d3f30554f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # LDC master #### Big news -- Frontend, druntime and Phobos are at version [2.110.0](https://dlang.org/changelog/2.110.0.html). (#4707, #4737) +- Frontend, druntime and Phobos are at version [2.110.0](https://dlang.org/changelog/2.110.0.html). (#4707, #4737, #4749) - LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64). (#4712) - Android: NDK for prebuilt package bumped from r26d to r27. (#4711) - ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)