[Issue 654] New: Const string member using implicit type inference gives garbage in certain situation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 5 20:06:02 PST 2006
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 at digitalmars.com
ReportedBy: chris at 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>
--
More information about the Digitalmars-d-bugs
mailing list