5195 – Forward references ignore const

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5195 - Forward references ignore const
Summary: Forward references ignore const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 critical
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2010年11月09日 12:46 UTC by Don
Modified: 2015年06月09日 05:11 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2010年11月09日 12:46:28 UTC
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?
Comment 1 Walter Bright 2010年11月14日 11:01:16 UTC
http://www.dsource.org/projects/dmd/changeset/755 


AltStyle によって変換されたページ (->オリジナル) /