Refactor dialog testing code to avoid gcc 10 -Wduplicated-branches

The old version resulted in

error: this condition has identical branches [-Werror=duplicated-branches]
    |                                 (dlg ? typeid(*dlg) : typeid(T)).name());
    |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

from gcc 10 when compiling with -O2.

Change the code to avoid using this condition entirely: not only this
avoids the warning, but it also makes it unnecessary to make
wxGetDialogClassDescription() function a template, so should result in
slightly faster compilation and smaller code size too.

No real changes.
This commit is contained in:
Vadim Zeitlin 2020-06-07 13:00:14 +02:00
parent 0941b25a97
commit f9780847b8

View File

@ -39,10 +39,10 @@ class WXDLLIMPEXP_FWD_CORE wxFileDialogBase;
class wxTestingModalHook; class wxTestingModalHook;
// This helper is used to construct the best possible name for the dialog of // This helper is used to construct the best possible name for the dialog of
// the given type using wxRTTI for this type, if any, and the C++ RTTI for // the given type using either wxRTTI or C++ RTTI.
// either the type T statically or the dynamic type of "dlg" if it's non-null. inline
template <class T> wxString
wxString wxGetDialogClassDescription(const wxClassInfo *ci, T* dlg = NULL) wxGetDialogClassDescription(const wxClassInfo *ci, const std::type_info& ti)
{ {
// We prefer to use the name from wxRTTI as it's guaranteed to be readable, // We prefer to use the name from wxRTTI as it's guaranteed to be readable,
// unlike the name returned by type_info::name() which may need to be // unlike the name returned by type_info::name() which may need to be
@ -51,8 +51,7 @@ wxString wxGetDialogClassDescription(const wxClassInfo *ci, T* dlg = NULL)
// than a readable but useless "wxDialog". // than a readable but useless "wxDialog".
if ( ci == wxCLASSINFO(wxDialog) ) if ( ci == wxCLASSINFO(wxDialog) )
{ {
return wxString::Format("dialog of type \"%s\"", return wxString::Format("dialog of type \"%s\"", ti.name());
(dlg ? typeid(*dlg) : typeid(T)).name());
} }
// We consider that an unmangled name is clear enough to be used on its own. // We consider that an unmangled name is clear enough to be used on its own.
@ -175,7 +174,7 @@ protected:
/// Returns description of the expected dialog (by default, its class). /// Returns description of the expected dialog (by default, its class).
virtual wxString GetDefaultDescription() const wxOVERRIDE virtual wxString GetDefaultDescription() const wxOVERRIDE
{ {
return wxGetDialogClassDescription<T>(wxCLASSINFO(T)); return wxGetDialogClassDescription(wxCLASSINFO(T), typeid(T));
} }
/** /**
@ -411,7 +410,7 @@ protected:
return wxString::Format return wxString::Format
( (
"A %s with title \"%s\"", "A %s with title \"%s\"",
wxGetDialogClassDescription(dlg->GetClassInfo(), dlg), wxGetDialogClassDescription(dlg->GetClassInfo(), typeid(*dlg)),
dlg->GetTitle() dlg->GetTitle()
); );
} }