[Issue 9051] Passing an immutable global with post-blit to a CTFE function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 21 02:13:18 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9051
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Summary|[CTFE] Working with |Passing an immutable global
|non-trivial immutable |with post-blit to a CTFE
|globals? |function
--- Comment #1 from Don <clugdbug at yahoo.com.au> 2012-11-21 02:13:04 PST ---
The error message is not coming from CTFE. Here's a simple case from a comment
in the compiler source code (declaration.c):
/* The problem is the following code:
* struct CopyTest {
* double x;
* this(double a) { x = a * 10.0;}
* this(this) { x += 2.0; }
* }
* const CopyTest z = CopyTest(5.3); // ok
* const CopyTest w = z; // not ok, postblit not run
* static assert(w.x == 55.0);
* because the postblit doesn't get run on the initialization of w.
*/
I think that if we didn't call this(this), wrong code would result.
There is at least a diagnostic bug here - if it must behave this way, the code
that creates the comma expression should be issuing the error.
Interestingly, if you move it inside a function, the result is different:
void foo()
{
pragma(msg, getSecond(set));
}
qqq.d(19): Error: static variable set cannot be referenced at compile time
qqq.d(19): called from here: __cpcttmp6.__cpctor(set)
qqq.d(19): called from here: getSecond((const const(Set) __cpcttmp6 =
__cpcttmp6.__cpctor(set);
, __cpcttmp6))
--
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