Skip to content

Commit

Permalink
Workaround a gcc warning for switch() { case X: return ...; } constructs
Browse files Browse the repository at this point in the history
Fixes warnings like the following one with gcc 9.3
```
/home/even/qgis/qgis/src/gui/qgsfilecontentsourcelineedit.cpp: In member function ‘virtual QString QgsPictureSourceLineEditBase::fileFilter() const’:
/home/even/qgis/qgis/src/gui/qgsfilecontentsourcelineedit.cpp:307:1: warning: control reaches end of non-void function [-Wreturn-type]
  307 | }
      | ^
```
  • Loading branch information
rouault authored and nyalldawson committed May 11, 2021
1 parent 26a09f6 commit a11baa0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -334,6 +334,7 @@ typedef unsigned long long qgssize;




QString geoWkt();
%Docstring
Wkt string that represents a geographic coord sys
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgis.h
Expand Up @@ -864,6 +864,26 @@ typedef unsigned long long qgssize;
#define FINAL final
#endif

#ifndef SIP_RUN
#if defined(__GNUC__) && !defined(__clang__)
// Workaround a GCC bug where a -Wreturn-type warning is emitted in constructs
// like:
// switch( mVariableThatCanOnlyBeXorY )
// {
// case X:
// return "foo";
// case Y:
// return "foo";
// }
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87951
#define DEFAULT_BUILTIN_UNREACHABLE \
default: \
__builtin_unreachable();
#else
#define DEFAULT_BUILTIN_UNREACHABLE
#endif
#endif // SIP_RUN

#ifdef SIP_RUN

/**
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgsfilecontentsourcelineedit.cpp
Expand Up @@ -289,20 +289,24 @@ QgsMessageBar *QgsAbstractFileContentSourceLineEdit::messageBar() const

///@cond PRIVATE


QString QgsPictureSourceLineEditBase::fileFilter() const
{
switch ( mFormat )
{
case Svg:
return tr( "SVG files" ) + " (*.svg)";
case Image:
{
QStringList formatsFilter;
const QByteArrayList supportedFormats = QImageReader::supportedImageFormats();
for ( const auto &format : supportedFormats )
{
formatsFilter.append( QString( QStringLiteral( "*.%1" ) ).arg( QString( format ) ) );
}
return QString( "%1 (%2);;%3 (*.*)" ).arg( tr( "Images" ), formatsFilter.join( QStringLiteral( " " ) ), tr( "All files" ) );
}
DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -313,7 +317,11 @@ QString QgsPictureSourceLineEditBase::selectFileTitle() const
case Svg:
return tr( "Select SVG File" );
case Image:
{
return tr( "Select Image File" );
}

DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -324,7 +332,11 @@ QString QgsPictureSourceLineEditBase::fileFromUrlTitle() const
case Svg:
return tr( "SVG From URL" );
case Image:
{
return tr( "Image From URL" );
}

DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -335,7 +347,11 @@ QString QgsPictureSourceLineEditBase::fileFromUrlText() const
case Svg:
return tr( "Enter SVG URL" );
case Image:
{
return tr( "Enter image URL" );
}

DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -346,7 +362,11 @@ QString QgsPictureSourceLineEditBase::embedFileTitle() const
case Svg:
return tr( "Embed SVG File" );
case Image:
{
return tr( "Embed Image File" );
}

DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -357,7 +377,11 @@ QString QgsPictureSourceLineEditBase::extractFileTitle() const
case Svg:
return tr( "Extract SVG File" );
case Image:
{
return tr( "Extract Image File" );
}

DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand All @@ -368,7 +392,10 @@ QString QgsPictureSourceLineEditBase::defaultSettingsKey() const
case Svg:
return QStringLiteral( "/UI/lastSVGDir" );
case Image:
{
return QStringLiteral( "/UI/lastImageDir" );
}
DEFAULT_BUILTIN_UNREACHABLE
}
}

Expand Down

0 comments on commit a11baa0

Please sign in to comment.