D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20576 - TemplateTypeParameter and TemplateValueParameter default values are not checked
Summary: TemplateTypeParameter and TemplateValueParameter default values are not checked
Status: RESOLVED DUPLICATE of issue 22540
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: accepts-invalid
: 8844 (view as issue list)
Depends on:
Blocks:
 
Reported: 2020-02-11 22:29 UTC by basile-z
Modified: 2022-01-28 09:56 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description basile-z 2020-02-11 22:29:20 UTC
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 basile-z 2020-02-11 22:31:37 UTC
TemplateValueParameter too:

---
void foo(ubyte u = 0xFF1)()
{
}

void main()
{
    foo!1();
}
---
Comment 2 Mathias LANG 2020-02-12 00:22:21 UTC
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 basile-z 2020-02-12 01:53:41 UTC
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 basile-z 2020-02-20 15:03:54 UTC
other example:

struct Foo {
    Foo opBinary(string op="-")(Foo f) {
        return Foo();
    }
}
void main() {
    auto Foo = Foo() + Foo();
}
Comment 5 basile-z 2020-02-20 15:05:12 UTC
*** Issue 8844 has been marked as a duplicate of this issue. ***
Comment 6 RazvanN 2022-01-28 09:56:18 UTC

*** This issue has been marked as a duplicate of issue 22540 ***