Bug 20576 – TemplateTypeParameter and TemplateValueParameter default values are not checked

Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-11T22:29:20Z
Last change time
2022-01-28T09:56:18Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Basile-z

Comments

Comment #0 by b2.temp — 2020-02-11T22:29:20Z
The following code should not compile --- void foo(T : Object = INVALID)(T t) { } void main() { foo(null); } --- because INVALID does not give a valid symbol, although it is not used in the call.
Comment #1 by b2.temp — 2020-02-11T22:31:37Z
TemplateValueParameter too: --- void foo(ubyte u = 0xFF1)() { } void main() { foo!1(); } ---
Comment #2 by pro.mathias.lang — 2020-02-12T00:22:21Z
I'm not sure that's an issue. In trivial cases like this the code is obviously wrong, but the only way we're going to realistically catch all these is by always instantiating the template with default parameters, which is 1) not always possible, 2) a waste of compilation time.
Comment #3 by b2.temp — 2020-02-12T01:53:41Z
I agree about the waste of time but keep the issue opened, just to be clear on the fact that the problem is already known.
Comment #4 by b2.temp — 2020-02-20T15:03:54Z
other example: struct Foo { Foo opBinary(string op="-")(Foo f) { return Foo(); } } void main() { auto Foo = Foo() + Foo(); }
Comment #5 by b2.temp — 2020-02-20T15:05:12Z
*** Issue 8844 has been marked as a duplicate of this issue. ***
Comment #6 by razvan.nitu1305 — 2022-01-28T09:56:18Z
*** This issue has been marked as a duplicate of issue 22540 ***