2009-07-03 13:52:08 UTC
Hi,
Take a look at the following code. I have compiled it with Visual C++ 2005 on Windows using FastFormat 0.4.2:
#include <string>
#include <iostream>
#include <fastformat/ff.hpp>
#include <fastformat/sinks/ostream.hpp>
#include <fastformat/format/specification_defect_handling/ignore_unreferenced_arguments_scope.hpp>
#include <fastformat/format/specification_defect_handling/ignore_missing_arguments_scope.hpp>
using namespace std;
template <typename S>
void TestIgnoreUnreferencedArgumentsScope(S& Sink)
{
// First see the (correct) fail
try
{
wstring format = L"[Arg 0: {0}, arg 1: {1}]\n";
ff::fmt(Sink, format, L"ARG0", L"ARG1", L"ARG2");
cout << "[FAIL] an exception should have been thrown\n";
}
catch(exception& Err)
{
cout << "[PASS] Caught exception: " << Err.what() << endl;
}
// The see if ignoring works
try
{
ff::ignore_unreferenced_arguments_scope scoper;
wstring format = L"[PASS] [Arg 0: {0}, arg 1: {1}]\n";
ff::fmt(Sink, format, L"ARG0", L"ARG1", L"ARG2");
}
catch(exception& Err)
{
cout << "[FAIL] Caught exception: " << Err.what() << endl;
}
}
template <typename S>
void TestIgnoreMissingArgumentsScope(S& Sink)
{
// First see the (correct) fail
try
{
wstring format = L"[Arg 0: {0}, arg 1: {1}]\n";
ff::fmt(Sink, format, L"ARG0");
cout << "[FAIL] an exception should have been thrown\n";
}
catch(exception& Err)
{
cout << "[PASS] Caught exception: " << Err.what() << endl;
}
// The see if ignoring works
try
{
ff::ignore_missing_arguments_scope scoper;
wstring format = L"[PASS] [Arg 0: {0}, arg 1: {1}]\n";
ff::fmt(Sink, format, L"ARG0"); // Crashes here
}
catch(exception& Err)
{
cout << "[FAIL] Caught exception: " << Err.what() << endl;
}
}
int wmain()
{
try
{
TestIgnoreUnreferencedArgumentsScope<wostream> (wcout);
TestIgnoreMissingArgumentsScope<wostream> (wcout);
}
catch (exception& Err)
{
cout << "Caught exception: " << Err.what() << endl;
}
catch (...)
{
cout << "Caught unhandled exception\n";
}
return 0;
}
When I run this I get an assertion on replacements.cpp in line 1046 with the error:
Expression: size_t(pattern_element.index) < argumentReferenceFlags.size()
Am I missing something obvious here?
Cheers,
Bart