Tue, 20 Jan 2009 16:36:09 +0100, Trass3r wrote: > Is there any way to output information at compile time other than > pragma(msg? > pragma is driving me crazy, the following doesn't work: > > auto members = __traits(allMembers, typeof(this)); > foreach(m; members) > { > pragma(msg, m); > } > > -> Error: string expected for message, not 'm' > > Though the docs clearly state: > allMembers: "An array of string literals is returned" > Also checked that, m is of type invariant(char)[]. > > Any ideas? -.-
Weird. The following code does not compile: class Cls { int bar; char[] baz; } string foo() { auto members = __traits(allMembers, Cls); return ""; } pragma(msg, foo()); >dmd -c test.d test.d(11): Error: cannot evaluate foo() at compile time test.d(11): pragma msg string expected for message, not 'foo()' Comment out the traits and it compiles. Traits are supposed to be compile-time. How's that possible for them to prevent compile-time evaluation?