Fix dangling else warnings at all wx(V)LogXXX calls

Earlier this was fixed for some but not all variants of wx(V)LogXXX.

See #11829.
This commit is contained in:
Lauri Nurmi
2019-12-20 15:19:29 +02:00
committed by Vadim Zeitlin
parent 1e7c2c8254
commit 32ead5a0ff
2 changed files with 116 additions and 41 deletions

View File

@@ -394,4 +394,66 @@ void LogTestCase::NoWarnings()
CPPUNIT_ASSERT_EQUAL( "If", m_log->GetLog(wxLOG_Error) );
}
// The following two functions (v, macroCompilabilityTest) are not run by
// any test, and their purpose is merely to guarantee that the wx(V)LogXXX
// macros compile without 'dangling else' warnings.
#pragma GCC diagnostic error "-Wdangling-else"
static void v(int x, ...) {
va_list list;
va_start(list, x);
if (true)
wxVLogGeneric(Info, "vhello generic %d", list);
if (true)
wxVLogTrace(wxTRACE_Messages, "vhello trace %d", list);
if (true)
wxVLogError("vhello error %d", list);
if (true)
wxVLogMessage("vhello message %d", list);
if (true)
wxVLogVerbose("vhello verbose %d", list);
if (true)
wxVLogWarning("vhello warning %d", list);
if (true)
wxVLogFatalError("vhello fatal %d", list);
if (true)
wxVLogSysError("vhello syserror %d", list);
#if wxUSE_GUI
if (true)
wxVLogStatus("vhello status %d", list);
#endif
if (true)
wxVLogDebug("vhello debug %d", list);
va_end(list);
}
void macroCompilabilityTest()
{
v(123, 456);
if (true)
wxLogGeneric(wxLOG_Info, "hello generic %d", 42);
if (true)
wxLogTrace(wxTRACE_Messages, "hello trace %d", 42);
if (true)
wxLogError("hello error %d", 42);
if (true)
wxLogMessage("hello message %d", 42);
if (true)
wxLogVerbose("hello verbose %d", 42);
if (true)
wxLogWarning("hello warning %d", 42);
if (true)
wxLogFatalError("hello fatal %d", 42);
if (true)
wxLogSysError("hello syserror %d", 42);
#if wxUSE_GUI
if (true)
wxLogStatus("hello status %d", 42);
#endif
if (true)
wxLogDebug("hello debug %d", 42);
}
#endif // wxUSE_LOG