digitalmars.D.bugs - [Issue 19769] New: CTFE format(): str[index] is used before
- d-bugmail puremagic.com (46/46) Mar 28 2019 https://issues.dlang.org/show_bug.cgi?id=19769
https://issues.dlang.org/show_bug.cgi?id=19769 Issue ID: 19769 Summary: CTFE format(): str[index] is used before initialized Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: elpenguino+D gmail.com trying to format the result of a const asCapitalized(string) at compile-time causes a used-before-initialized error in std.utf.decode(), as demonstrated below: ``` import std.uni; import std.format; static immutable x = format("%s", cast(const)"test".asCapitalized); ``` results in this error: ``` /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(1132): Error: str[index] is used before initialized /dlang/dmd/linux/bin64/../../src/phobos/std/uni.d(9143): originally uninitialized here /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(3457): called from here: decode(str, i) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(4233): called from here: formatElement(w, e, f) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(1854): called from here: formatValueImpl(w, val, f) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(3552): called from here: formatValue(w, val, f) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(4233): called from here: formatElement(w, e, f) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(1854): called from here: formatValueImpl(w, val, f) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(575): called from here: formatValue(w, _param_2, spec) /dlang/dmd/linux/bin64/../../src/phobos/std/format.d(6403): called from here: formattedWrite(w, fmt, _param_1) onlineapp.d(3): called from here: format("%s", asCapitalized("test")) ``` --
Mar 28 2019