From cdef013a8a9b10747267f5fa876b7d643ca2fd59 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 24 Jan 2016 15:59:35 +0100 Subject: [PATCH] Suppress harmless warnings about string literals in test code We rely on string literals being of non-const char or wchar_t pointer type for this code to compile, even if this results in warnings, so we're not interested in these warnings in the test code itself. --- tests/strings/strings.cpp | 9 +++++++++ tests/strings/vararg.cpp | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 0c96e1424a..a29c454664 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -968,6 +968,12 @@ void StringTestCase::DoCStrDataTernaryOperator(bool cond) wxString s("foo"); + // Using literal strings in ternary operator below results in these + // warnings, but they're unavoidable if we want such code to continue to + // compile at all, as it used to in pre-3.0 versions, so just suppress them. + wxGCC_WARNING_SUPPRESS(write-strings) + wxCLANG_WARNING_SUPPRESS(c++11-compat-deprecated-writable-strings) + const wchar_t *wcStr = L"foo"; CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : wcStr)) ); CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : L"foo")) ); @@ -980,6 +986,9 @@ void StringTestCase::DoCStrDataTernaryOperator(bool cond) CPPUNIT_ASSERT( CheckStr(s, (cond ? mbStr : s.c_str())) ); CPPUNIT_ASSERT( CheckStr(s, (cond ? "foo" : s.c_str())) ); + wxGCC_WARNING_RESTORE(write-strings) + wxCLANG_WARNING_RESTORE(c++11-compat-deprecated-writable-strings) + wxString empty(""); CPPUNIT_ASSERT( CheckStr(empty, (cond ? empty.c_str() : wxEmptyString)) ); CPPUNIT_ASSERT( CheckStr(empty, (cond ? wxEmptyString : empty.c_str())) ); diff --git a/tests/strings/vararg.cpp b/tests/strings/vararg.cpp index b7e51eab14..80ded5ecf8 100644 --- a/tests/strings/vararg.cpp +++ b/tests/strings/vararg.cpp @@ -101,9 +101,16 @@ void VarArgTestCase::StringPrintf() CPPUNIT_ASSERT( s2 == "value=FooBar;" ); // this tests correct passing of wxCStrData constructed from string - // literal: + // literal (and we disable the warnings related to the use of a literal + // here because we want to test that this compiles, even with warnings): + wxGCC_WARNING_SUPPRESS(write-strings) + wxCLANG_WARNING_SUPPRESS(c++11-compat-deprecated-writable-strings) + bool cond = true; s2.Printf(wxT("foo %s"), !cond ? s.c_str() : wxT("bar")); + + wxGCC_WARNING_RESTORE(write-strings) + wxCLANG_WARNING_RESTORE(c++11-compat-deprecated-writable-strings) } void VarArgTestCase::CharPrintf()