[Issue 3688] Can't have declaration with assignment to const/immutable inside if condition

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 18 20:23:52 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=3688


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |k.hara.pg at gmail.com
            Version|2.036                       |D2


--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2011-04-18 20:20:18 PDT ---
More comprehensive code.
----
struct S
{
    int v;
    this(int n) { v = n; }
    const bool opCast(T:bool)() { return true; }
}
void main()
{
    if (int a = 1)
        assert(a == 1);
    else assert(0);

    if (const int a = 2)
        assert(a == 2);
    else assert(0);

    if (immutable int a = 3)
        assert(a == 3);
    else assert(0);

    if (auto s = S(10))
        assert(s.v == 10);
    else assert(0);

    if (auto s = const(S)(20))
        assert(s.v == 20);
    else assert(0);

    if (auto s = immutable(S)(30))
        assert(s.v == 30);
    else assert(0);
}
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list