Bug 5394 – Changing the order of writing pragma(msg, (...).mangleof) changes the result

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-12-31T17:18:00Z
Last change time
2012-06-01T22:18:22Z
Assigned to
nobody
Creator
wfunction

Comments

Comment #0 by wfunction — 2010-12-31T17:18:28Z
I have this code below: // Code ================================= private template Dummy(sth...) { struct Hook { } } template myMangledName(sth...) if (sth.length == 1) { enum string myMangledName = Dummy!(sth[0]).Hook.mangleof; pragma(msg, Dummy!().Hook.mangleof); pragma(msg, Dummy!(sth).Hook.mangleof); } class Temp { int Field; pragma(msg, "IGNORE THIS... ", myMangledName!(Field)); } // End Code ============================= When I compile it with DMD 2.051, I get this text printed: IGNORE THIS... S4meta10__T5DummyZ4Hook S4meta4Temp32__T5DummyS19_D4meta4Temp5FieldiZ4Hook S4meta4Temp32__T5DummyS19_D4meta4Temp5FieldiZ4Hook However, if I compile this: // Code ================================= private template Dummy(sth...) { struct Hook { } } template myMangledName(sth...) if (sth.length == 1) { enum string myMangledName = Dummy!(sth[0]).Hook.mangleof; pragma(msg, Dummy!(sth).Hook.mangleof); pragma(msg, Dummy!().Hook.mangleof); //Notice that the above two are switched } class Temp { int Field; pragma(msg, "IGNORE THIS... ", myMangledName!(Field)); } // End Code ============================= I get this result: IGNORE THIS... S4meta4Temp32__T5DummyS19_D4meta4Temp5FieldiZ4Hook S4meta10__T5DummyZ4Hook S4meta4Temp32__T5DummyS19_D4meta4Temp5FieldiZ4Hook which is obviously different from the last one. Is this a bug?
Comment #1 by k.hara.pg — 2012-06-01T07:29:04Z
This is not a bug. Test with following code. private template Dummy(sth...) { struct Hook { } } template myMangledName(sth...) if (sth.length == 1) { enum string myMangledName = Dummy!(sth[0]).Hook.mangleof; version(A) { pragma(msg, "1[", Dummy!().Hook.mangleof, "]"); pragma(msg, "2[", Dummy!(sth).Hook.mangleof, "]"); } version(B) { pragma(msg, "2[", Dummy!(sth).Hook.mangleof, "]"); pragma(msg, "1[", Dummy!().Hook.mangleof, "]"); } } class Temp { int Field; pragma(msg, "IGNORE THIS... ", myMangledName!(Field)); } output: c:\d> dmd -version=A -run test.d IGNORE THIS... 1[S4test10__T5DummyZ4Hook] 2[S4test4Temp32__T5DummyS19_D4test4Temp5FieldiZ4Hook] S4test4Temp32__T5DummyS19_D4test4Temp5FieldiZ4Hook c:\d> dmd -version=B -run test.d IGNORE THIS... 2[S4test4Temp32__T5DummyS19_D4test4Temp5FieldiZ4Hook] 1[S4test10__T5DummyZ4Hook] S4test4Temp32__T5DummyS19_D4test4Temp5FieldiZ4Hook
Comment #2 by wfunction — 2012-06-01T17:50:55Z
Sorry, could you please explain how/why you say that is not a bug? o.O
Comment #3 by k.hara.pg — 2012-06-01T21:25:08Z
(In reply to comment #2) > Sorry, could you please explain how/why you say that is not a bug? o.O See the output of my code. In both version(A) and version(B), pragma(msg, "1[", Dummy!().Hook.mangleof, "]"); prints "1[S4test10__T5DummyZ4Hook]", and pragma(msg, "2[", Dummy!(sth).Hook.mangleof, "]"); prints "2[S4test4Temp32__T5DummyS19_D4test4Temp5FieldiZ4Hook]". It isn't dependent to the order. There is no bug. And, with current dmd implementation, pragma(msg, e1, e2, ...); is interpreted as: eval e1 -> print e1 -> eval e2 -> print e2 -> ... So the printing of pragmas in myMangledName template runs *before* the printing of myMangledName!(Field) result. (I can agree it is compiler implementation dependent behavior, but cannot agree to mark it as a bug.)
Comment #4 by wfunction — 2012-06-01T21:40:42Z
Oh lol. What version of DMD are you on? Probably just got fixed lol, since they didn't have the same output when I checked.
Comment #5 by k.hara.pg — 2012-06-01T21:46:31Z
I'm using 2.060head.
Comment #6 by wfunction — 2012-06-01T22:18:22Z
That's probably why lol. Thanks for posting.