Index: boost/spirit/home/karma/numeric/int.hpp =================================================================== --- boost/spirit/home/karma/numeric/int.hpp (Revision 76795) +++ boost/spirit/home/karma/numeric/int.hpp (Arbeitskopie) @@ -207,12 +207,47 @@ template static bool insert_int(OutputIterator& sink, Attribute const& attr) { - return sign_inserter::call(sink, traits::test_zero(attr) - , traits::test_negative(attr), force_sign) && - int_inserter::call(sink + // I have serialized the calls to better follow with the debugger what's going on. + bool is_zero = traits::test_zero(attr); + bool is_neg = traits::test_negative(attr); + // Until here everything seems OK, *attr still has its value. + // I can use, e.g., the attribute in a function call. + Attribute attr_copy = dummy_function(attr); +// bool r1 = sign_inserter::call(sink, is_zero +// , is_neg, force_sign); + // After the sign_inserter call, *attr becomes surprisingly zero. + // Therefore, I inlined the important code parts to output the sign. + if (is_neg) { + *sink = '-'; + // After putting the character into the sink, the *attr becomes zero. + // Why??? This happens consistently unimportant whether it's + // compiled using g++ or clang++ on Linux or Mac OS X. Is the sink + // not correctly constructed and leaks memory? + ++sink; + } else if (force_sign) { + if (is_zero) { + *sink = ' '; + } else { + *sink = '+'; + } + ++sink; + } + bool r1 = true; + bool r2 = int_inserter::call(sink , traits::get_absolute_value(attr)); + return r1 && r2; +// return sign_inserter::call(sink, traits::test_zero(attr) +// , traits::test_negative(attr), force_sign) && +// int_inserter::call(sink +// , traits::get_absolute_value(attr)); } - + + // Dummy function for pure diagnostic reasons. It just returns a copy of the attribute. + template + static Attribute dummy_function(Attribute const& attr) { + return attr; + }; + public: template struct attribute @@ -237,7 +272,6 @@ { if (!traits::has_optional_value(attr)) return false; // fail if it's an uninitialized optional - return insert_int(sink, traits::extract_from(attr, context)) && delimit_out(sink, d); // always do post-delimiting }