Summary: const and invariant struct members do not behave
                    according to spec
           Product: D
           Version: 2.035
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Lars T. Kyllingstad <> 2009-10-29 
04:52:34 PDT ---
When struct members are declared const or invariant, they seem to become
manifest constants. Example:

  struct Foo { const int bar = 123; }
  writeln(Foo.sizeof);   // Prints "1", not "4"

  Foo foo;
  auto p = &;     // Error: constant 123 is not an lvalue

The same happens if const is replaced with immutable. According to the spec it
should be possible to take the address of const/immutable variables, and in the
case of const it is even considered well-defined behaviour to change their
value after casting them to non-const. I see no reason why this shouldn't apply
to structs as well.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to