bug in pragma?

JS js.mdnq at gmail.com
Thu Jul 4 15:48:49 PDT 2013


On Thursday, 4 July 2013 at 22:35:27 UTC, Jonathan M Davis wrote:
> 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

This is simply wrong. If s could not be used at compile time then 
the mixin could not be used at compile time... yet it can be and 
is being used and works fine when the pragma is removed... and 
one can even pragma the template name after the function and it 
will work.




More information about the Digitalmars-d mailing list