Commit 543be095 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Remove C++11 specific version of SafeSNPrintf()

Remove C++11 specific version of SafeSNPrintf() as we don't really use C++11 yet
and adding code like this adds a maintenance cost. For example, the code in
question does not build with gcc 4.7 despite C++11 support being enabled.

R=Nico
BUG=233330

Review URL: https://codereview.chromium.org/102993006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239227 0039d316-1c4b-4281-b951-d872f2087c98
parent 001e547e
......@@ -104,8 +104,6 @@ typedef long ssize_t;
// like SafeSPrintf(buf, "%p %d", 1, 2) results in "%p 2"). See above for
// the use of RAW_CHECK() in debug builds, though.
//
// The pre-C++11 version cannot handle more than ten arguments.
//
// Basic example:
// char buf[20];
// base::strings::SafeSPrintf(buf, "The answer: %2d", 42);
......@@ -190,29 +188,8 @@ BASE_EXPORT size_t GetSafeSPrintfSSizeMaxForTest();
} // namespace internal
#if __cplusplus >= 201103 // C++11
template<typename... Args>
ssize_t SafeSNPrintf(char* buf, size_t N, const char* fmt, Args... args) {
// Use Arg() object to record type information and then copy arguments to an
// array to make it easier to iterate over them.
const internal::Arg arg_array[] = { args... };
return internal::SafeSNPrintf(buf, N, fmt, arg_array, arraysize(arg_array));
}
template<size_t N, typename... Args>
ssize_t SafeSPrintf(char (&buf)[N], const char* fmt, Args... args) {
// Use Arg() object to record type information and then copy arguments to an
// array to make it easier to iterate over them.
const internal::Arg arg_array[] = { args... };
return internal::SafeSNPrintf(buf, N, fmt, arg_array, arraysize(arg_array));
}
#else // Pre-C++11
// TODO(markus): C++11 has a much more concise and readable solution for
// expressing what we are doing here. Delete the fall-back code for older
// compilers as soon as we have fully switched to C++11.
// expressing what we are doing here.
template<class T0, class T1, class T2, class T3, class T4,
class T5, class T6, class T7, class T8, class T9>
......@@ -426,7 +403,6 @@ ssize_t SafeSPrintf(char (&buf)[N], const char* fmt, T0 arg0) {
const internal::Arg arg_array[] = { arg0 };
return internal::SafeSNPrintf(buf, N, fmt, arg_array, arraysize(arg_array));
}
#endif
// Fast-path when we don't actually need to substitute any arguments.
BASE_EXPORT ssize_t SafeSNPrintf(char* buf, size_t N, const char* fmt);
......
......@@ -264,18 +264,6 @@ TEST(SafeSPrintfTest, NArgs) {
EXPECT_EQ(10, SafeSNPrintf(buf, 11, "%c%c%c%c%c%c%c%c%c%c",
1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
EXPECT_EQ("\1\2\3\4\5\6\7\10\11\12", std::string(buf));
// C++11 is smart enough to handle variadic template arguments. It can
// deal with arbitrary numbers of arguments.
#if __cplusplus >= 201103 // C++11
EXPECT_EQ(11, SafeSPrintf(buf, "%c%c%c%c%c%c%c%c%c%c%c",
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11));
EXPECT_EQ("\1\2\3\4\5\6\7\10\11\12\13", std::string(buf));
EXPECT_EQ(11, SafeSNPrintf(buf, 12, "%c%c%c%c%c%c%c%c%c%c%c",
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11));
EXPECT_EQ("\1\2\3\4\5\6\7\10\11\12\13", std::string(buf));
#endif
}
TEST(SafeSPrintfTest, DataTypes) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment