Bug 9681 – std.variant.Algebraic with const members
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-03-10T07:13:30Z
Last change time
2019-12-23T09:43:35Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-03-10T07:13:30Z
This code compiles with dmd 2.063alpha:
import std.variant: Algebraic;
struct A {}
alias Foo = Algebraic!(A);
void main() {
const A bar;
auto spam = Foo(bar); // line 6.
assert(spam.peek!(const A)); // No assertion failure
assert(spam.peek!A); // Assertion failure
}
And at runtime it asserts at line 8:
core.exception.AssertError@test2(8): Assertion failure
I think that maybe line 6 should be refused, otherwise it becomes hard to catch all possible things that can be inside "spam". In this program bar is like an Algebraic!(A, const A).