Bug 10892 – Compilation continues after static assert failing in templates
Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-25T14:37:59Z
Last change time
2023-03-27T12:41:03Z
Assigned to
No Owner
Creator
Temtaime
Comments
Comment #0 by temtaime — 2013-08-25T14:37:59Z
template A() {
static assert(false, `error`);
enum A = A!();
}
void main() {
enum B = A!();
}
Output:
Error: forward reference of variable A
Error: static assert "error"
instantiated from here: A!()
Expected output:
Error: static assert "error"
instantiated from here: A!()
If static assert fails and there is much code after it, it makes a trouble.
Comment #1 by razvan.nitu1305 — 2023-03-27T12:41:03Z
This issue is invalid. There is no order relationship between the declarations inside a template scope, so the expectation that the static assert is evaluated before the enum declaration is misguided. The general case is that the assert actually tests something that is defined inside the the template declaration scope, therefore we shouldn't expect a relationship order.