Ticket #6126: boost_spirit_home_karma_numeric_int_diagnostic.patch
File boost_spirit_home_karma_numeric_int_diagnostic.patch, 2.9 KB (added by , 11 years ago) |
---|
-
boost/spirit/home/karma/numeric/int.hpp
207 207 template <typename OutputIterator, typename Attribute> 208 208 static bool insert_int(OutputIterator& sink, Attribute const& attr) 209 209 { 210 return sign_inserter::call(sink, traits::test_zero(attr) 211 , traits::test_negative(attr), force_sign) && 212 int_inserter<Radix, CharEncoding, Tag>::call(sink 210 // I have serialized the calls to better follow with the debugger what's going on. 211 bool is_zero = traits::test_zero(attr); 212 bool is_neg = traits::test_negative(attr); 213 // Until here everything seems OK, *attr still has its value. 214 // I can use, e.g., the attribute in a function call. 215 Attribute attr_copy = dummy_function(attr); 216 // bool r1 = sign_inserter::call(sink, is_zero 217 // , is_neg, force_sign); 218 // After the sign_inserter call, *attr becomes surprisingly zero. 219 // Therefore, I inlined the important code parts to output the sign. 220 if (is_neg) { 221 *sink = '-'; 222 // After putting the character into the sink, the *attr becomes zero. 223 // Why??? This happens consistently unimportant whether it's 224 // compiled using g++ or clang++ on Linux or Mac OS X. Is the sink 225 // not correctly constructed and leaks memory? 226 ++sink; 227 } else if (force_sign) { 228 if (is_zero) { 229 *sink = ' '; 230 } else { 231 *sink = '+'; 232 } 233 ++sink; 234 } 235 bool r1 = true; 236 bool r2 = int_inserter<Radix, CharEncoding, Tag>::call(sink 213 237 , traits::get_absolute_value(attr)); 238 return r1 && r2; 239 // return sign_inserter::call(sink, traits::test_zero(attr) 240 // , traits::test_negative(attr), force_sign) && 241 // int_inserter<Radix, CharEncoding, Tag>::call(sink 242 // , traits::get_absolute_value(attr)); 214 243 } 215 244 245 // Dummy function for pure diagnostic reasons. It just returns a copy of the attribute. 246 template<typename Attribute> 247 static Attribute dummy_function(Attribute const& attr) { 248 return attr; 249 }; 250 216 251 public: 217 252 template <typename Context, typename Unused> 218 253 struct attribute … … 237 272 { 238 273 if (!traits::has_optional_value(attr)) 239 274 return false; // fail if it's an uninitialized optional 240 241 275 return insert_int(sink, traits::extract_from<T>(attr, context)) && 242 276 delimit_out(sink, d); // always do post-delimiting 243 277 }