Thread overview |
---|
December 06, 2006 [Issue 654] New: Const string member using implicit type inference gives garbage in certain situation | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=654 Summary: Const string member using implicit type inference gives garbage in certain situation Product: D Version: 0.176 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P3 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: chris@inventivedingo.com Suppose we have a class (call it A), with a const member called MY_CONST_STRING that is initialised to a char array using implicit type inference. Suppose also that at some point in the code we refer to it as "A.MY_CONST_STRING". Then, if we print "MY_CONST_STRING" from within the class A, garbage will be produced. However, if we never refer to "A.MY_CONST_STRING" anywhere, then printing "MY_CONST_STRING" will work as expected (without producing garbage). It seems to be necessary that the member is a char array, and that implicit type inference is used. (Declaring it as static const char[] MY_CONST_... will cause everything to work.) This is easier to see in code: --------- testbug.d --------- import std.stdio; class A { static const MY_CONST_STRING = "hello"; this() { // This will either print garbage or throw a UTF exception. // But if never_called() is commented out, then it will work. writefln("%s", MY_CONST_STRING); } } void never_called() { // This can be anything; there just needs to be a reference to // A.MY_CONST_STRING somewhere. writefln("%s", A.MY_CONST_STRING); } void main() { A a = new A(); } --------- D:\D>dmd -run testbug ♣ Error: 4invalid UTF-8 sequence D:\D> -- |
December 27, 2006 [Issue 654] Const string member using implicit type inference gives garbage in certain situation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=654 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #1 from bugzilla@digitalmars.com 2006-12-27 02:01 ------- Fixed DMD 0.178 -- |
December 30, 2006 [Issue 654] Const string member using implicit type inference gives garbage in certain situation | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=654 ------- Comment #2 from thomas-dloop@kuehne.cn 2006-12-30 09:49 ------- Added to DStress as http://dstress.kuehne.cn/run/o/odd_bug_11_A.d http://dstress.kuehne.cn/run/o/odd_bug_11_B.d http://dstress.kuehne.cn/run/o/odd_bug_11_C.d http://dstress.kuehne.cn/run/o/odd_bug_11_D.d http://dstress.kuehne.cn/run/o/odd_bug_11_E.d -- |
Copyright © 1999-2021 by the D Language Foundation