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.
This commit is contained in:
Vadim Zeitlin
2016-01-24 15:59:35 +01:00
parent 96f5a24f6d
commit cdef013a8a
2 changed files with 17 additions and 1 deletions

View File

@@ -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())) );

View File

@@ -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()