bug in pragma?

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 4 15:35:09 PDT 2013


On Friday, July 05, 2013 00:29:20 JS wrote:
> import std.stdio, std.cstream;
> 
> 
> template test(alias x)
> {
> 	string func()
> 	{
> 		string s = "beta";
> 		//pragma(msg, s);
> 		return s;
> 	}
> 	enum test = func();
> }
> 
> void main(string[] args)
> {
> 	mixin test!("alpha");
> 	din.getc();
> }
> 
> When I try to display a compiler msg using pragma on a string
> variable the mixin fails. Commenting out the pragma allows the
> mixin to work.
> 
> While there may be some internal reason this shouldn't work it
> seems quite unnatural and took me a while to figure out it was
> pragma causing the problem in my code.

I wouldn't ever expect that pragma to work. pramga is a compile-time construct 
and requires compile-time arguments, whereas s is normal, local variable and 
not usable at compile-time except when the function it's in is called as part 
of CTFE. It would work if s were an enum, because the value of an enum must be 
known at compile time, but that's not the case with a normal string variable.

- Jonathan M Davis


More information about the Digitalmars-d mailing list