5865 – __dollar cannot be read at compile time

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5865 - __dollar cannot be read at compile time
Summary: __dollar cannot be read at compile time
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2011年04月19日 18:06 UTC by changlon
Modified: 2011年04月30日 11:30 UTC (History)
2 users (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 changlon 2011年04月19日 18:06:47 UTC
this working on dmd 2.052 release, throw error on dmd git master .
------------------------------------------
class Test1(string name, string file = __FILE__){
	static const _file	= file ;
	void test1(){
		static const string file2 = _file[0..$] ;
	}
}
void main(){
	auto obj	= new Test1!"Test1" ;
	obj.test1();
}
-----------------------------------------
test.d(5): Error: variable __dollar cannot be read at compile time
test.d(5): Error: variable __dollar cannot be read at compile time
test.d(10): Error: template instance test.Test1!("Test1") error instantiating
Comment 1 Don 2011年04月20日 02:06:21 UTC
PATCH dsymbol.c, line 1181.
 if (!*pvar) // if not already initialized
 { /* Create variable v and set it to the value of ,ドル
 * which will be a constant.
 */
 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL);
 if (ce->op == TOKvar)
 { // if ce is const, get its initializer
- ce = fromConstInitializer(WANTvalue, ce);
+ ce = fromConstInitializer(WANTvalue | WANTexpand, ce);
 }
 if (ce->op == TOKstring)
 { /* It is for a string literal, so the
 * length will be a const.
 */


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