From cca6459b4fe68593137cb0f3ede7d1415cdbd522 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 29 Jan 2018 14:42:26 -0800 Subject: base: Remove the ability to cprintf stringstreams directly. The cprintf functions don't know ahead of time what format characters are going to be used with what underlying data types, and so any type must be minimally usable with the default specialization of format_integer, format_char, format_float and format_string. All of those functions ultimately print their parameter with out << data except the one which prints stringstreams. That function accesses the buffer of the string stream with .str(), and then prints that instead. That should technically work out ok as long as stringstreams are only printed using %s, but there's no way to guarantee that ahead of time. To avoid that problem, and because gem5 doesn't ever actually use the ability to print stringstreams directly, this change removes that feature and modifies the corresponding part of the unit test. If we ever do want to print the contents of a string stream, it won't be difficult to add a .str() to it. Change-Id: Id902eaff042b96b374efe0183e5e3be9626e8c88 Reviewed-on: https://gem5-review.googlesource.com/7642 Reviewed-by: Jason Lowe-Power Maintainer: Gabe Black --- src/base/cprintf_formats.hh | 4 ---- src/base/cprintftest.cc | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/base/cprintf_formats.hh b/src/base/cprintf_formats.hh index 4c78fdf50..f55fb955e 100644 --- a/src/base/cprintf_formats.hh +++ b/src/base/cprintf_formats.hh @@ -337,10 +337,6 @@ inline void format_string(std::ostream &out, const T &data, Format &fmt) { _format_string(out, data, fmt); } -inline void -format_string(std::ostream &out, const std::stringstream &data, Format &fmt) -{ _format_string(out, data.str(), fmt); } - } // namespace cp #endif // __CPRINTF_FORMATS_HH__ diff --git a/src/base/cprintftest.cc b/src/base/cprintftest.cc index 86694ed83..3a1b97e40 100644 --- a/src/base/cprintftest.cc +++ b/src/base/cprintftest.cc @@ -166,7 +166,7 @@ TEST(CPrintf, Types) std::stringstream foo2; foo2 << "stringstream test"; - ccprintf(ss, "%s\n", foo2); + ccprintf(ss, "%s\n", foo2.str()); EXPECT_EQ(ss.str(), "stringstream test\n"); ss.str(""); -- cgit v1.2.3