Bug 8260 – * used three or more times on an array inside std.format.formattedRead and not guarded by template constraint
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-06-18T05:12:00Z
Last change time
2017-03-22T12:22:00Z
Keywords
bootcamp
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-06-18T05:12:17Z
import std.format;
void main() {
int[3] row;
auto text = "10 20 30";
formattedRead(text, "%(%d %)", row);
}
DMD 2.060alpha:
...\dmd2\src\phobos\std\format.d(555): Error: using * on an array is deprecated; use *(_param_2).ptr instead
...\dmd2\src\phobos\std\format.d(566): Error: using * on an array is deprecated; use *(_param_2).ptr instead
test.d(5): Error: template instance std.format.formattedRead!(string,char,uint[3u]) error instantiating
Part inside formattedRead, that uses * three times:
alias typeof(*args[0]) A;
static if (isTuple!A)
{
foreach (i, T; A.Types)
{
(*args[0])[i] = unformatValue!(T)(r, spec);
skipUnstoredFields();
}
}
else
{
*args[0] = unformatValue!(A)(r, spec);
Comment #1 by k.hara.pg — 2012-06-18T05:47:29Z
The bug is in your code.
void main() {
int[3] row;
auto text = "10 20 30";
//formattedRead(text, "%(%d %)", row); // bad
formattedRead(text, "%(%d %)", &row); // OK
}
Comment #2 by timon.gehr — 2012-06-18T06:11:30Z
Phobos should catch the error with a template constraint instead of showing confusing errors in the template body.
Comment #3 by b2.temp — 2015-11-27T16:18:12Z
*** Issue 12450 has been marked as a duplicate of this issue. ***
Comment #4 by github-bugzilla — 2017-02-02T16:28:52Z