www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5195] New: Forward references ignore const

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5195

           Summary: Forward references ignore const
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2010-11-09 12:46:28 PST ---
alias typeof(foo) food;
const int * foo = null;
alias typeof(foo) good;
static assert( is (food == good));
---------------
bug.d(5): Error: static assert  (is(int* == const(int*))) is false
---------------

This is the root cause of many subtle and mysterious bugs. For example, bug
2080 "ICE(mangle.c) alias corrupts type inference of static variables"

The problem is that, in something like "const int * foo", a
StorageClassDeclaration is used to specify "const", and "int * foo" is a member
of it. When semantic is run on the StorageClassDeclaration, the
const/immutable/shared gets transferred into the members.
BUT when there is a forward reference, StorageClassDeclaration::semantic() has
not yet been run. All its member declarations haven't got their storage class
yet. So the forward reference gets the type without const.

Although const is D2-specific, the same issues arise in D1 as well, because it
uses StorageClassDeclaration too.

I'm not sure of the best way to solve this. I don't understand why
StorageClassDeclaration exists at all -- why isn't the storage class applied by
the parser, instead of in the semantic pass?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5195


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #1 from Walter Bright <bugzilla digitalmars.com> 2010-11-14
11:01:16 PST ---
http://www.dsource.org/projects/dmd/changeset/755

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