Thread overview |
---|
September 29, 2008 [Issue 2379] New: CTFE fails to evaluate if unless it is very straightforward | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2379 Summary: CTFE fails to evaluate if unless it is very straightforward Product: D Version: 2.019 Platform: PC OS/Version: Windows Status: NEW Severity: critical Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: 2korden@gmail.com First attempt: ----------- template Test0(invariant(char)[] text) { auto Test0 = text; } writefln(Test0!("hello")); // success pragma(msg, Test0!("hello")); // failure: // pragma msg string expected for message, not 'Test0' Let's replace invariant(char)[] with alias :( ----------- template Test0(alias text) { auto Test0 = text; } pragma(msg, Test0!("hello")); // success Let's make it slightly more complex: ----------- template Test0(alias text) { auto Test0 = text[0..1]; } pragma(msg, Test0!("hello")); // failure: // pragma msg string expected for message, not 'Test0' Other example: ----------- template Test0(invariant(char)[] text) { auto Test0 = text; } template Test1(invariant(char)[] text) { auto Test1 = Test0!(text); } writefln(Test0!("hello")); // success writefln(Test1!("hello")); // failure: // Error: non-constant expression Test0 -- |
September 30, 2008 [Issue 2379] CTFE fails unless it is very straightforward | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2379 ------- Comment #1 from shro8822@vandals.uidaho.edu 2008-09-29 19:02 ------- Something is wrong here. The examples don't use CTFE. Is the title wrong? -- |
September 30, 2008 [Issue 2379] CTFE fails unless it is very straightforward | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2379 ------- Comment #2 from snake.scaly@gmail.com 2008-09-30 07:56 ------- Everything works as expected. template Test0(invariant(char)[] text) { auto Test0 = text; } effectively declares invariant(char)[] Test0 = "hello"; which is a variable initialized at runtime. The correct way to write this template is template Test0(invariant(char)[] text) { enum Test0 = text; } which declares a manifest constant. -- |
October 02, 2008 [Issue 2379] CTFE fails unless it is very straightforward | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2379 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #3 from bugzilla@digitalmars.com 2008-10-02 04:05 ------- Sergey is correct. -- |
Copyright © 1999-2021 by the D Language Foundation