www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Strange exception, with EXTREMELY SIMPLE toString() in a struct

reply Enjoys Math <enjoysmath gmail.com> writes:
Exception Message:
First-chance exception: std.format.FormatException Unterminated 
format specifier: "%" at 
C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828)

[CODE]
module set;
import std.conv;

struct Set(T) {
	string toString() const {
		auto str = "{";
		return str;
	}
}

unittest {
	import std.stdio;
	auto A = Set!int();
	writeln(A);
}
[/CODE]
Dec 07 2015
next sibling parent Marc =?UTF-8?B?U2Now7x0eg==?= <schuetzm gmx.net> writes:
On Monday, 7 December 2015 at 08:17:27 UTC, Enjoys Math wrote:
 Exception Message:
 First-chance exception: std.format.FormatException Unterminated 
 format specifier: "%" at 
 C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828)

 [CODE]
 module set;
 import std.conv;

 struct Set(T) {
 	string toString() const {
 		auto str = "{";
 		return str;
 	}
 }

 unittest {
 	import std.stdio;
 	auto A = Set!int();
 	writeln(A);
 }
 [/CODE]
Works fine for me (Linux x86_64, DMD 2.069). Which version are you using exactly? Also, are you sure you're not accidentally running an outdated executable, or your executable doesn't actually match the code you posted? It doesn't invoke format at all.
Dec 07 2015
prev sibling next sibling parent Radu <radu void.null> writes:
On Monday, 7 December 2015 at 08:17:27 UTC, Enjoys Math wrote:
 Exception Message:
 First-chance exception: std.format.FormatException Unterminated 
 format specifier: "%" at 
 C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828)

 [CODE]
 module set;
 import std.conv;

 struct Set(T) {
 	string toString() const {
 		auto str = "{";
 		return str;
 	}
 }

 unittest {
 	import std.stdio;
 	auto A = Set!int();
 	writeln(A);
 }
 [/CODE]
Are you running this in VisualD plugin? This is the only place I get that exception. Running it from the command line works as expected on 2.069.1 win32
Dec 07 2015
prev sibling parent rumbu <rumbu rumbu.ro> writes:
On Monday, 7 December 2015 at 08:17:27 UTC, Enjoys Math wrote:
 Exception Message:
 First-chance exception: std.format.FormatException Unterminated 
 format specifier: "%" at 
 C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828)

 [CODE]
 module set;
 import std.conv;

 struct Set(T) {
 	string toString() const {
 		auto str = "{";
 		return str;
 	}
 }

 unittest {
 	import std.stdio;
 	auto A = Set!int();
 	writeln(A);
 }
 [/CODE]
This is caused in fact by a correct unittest assertion in format.d: f = FormatSpec("a%%b%%c%"); w.clear(); assertThrown!FormatException(f.writeUpToNextSpec(w)); <-- here assert(w.data == "a%b%c" && f.trailing == "%"); You can add std.Format.FormatException to the Exception Settings (Debug -> Exceptions) and untick the Thrown checkbox.
Dec 07 2015