From 10ba46874825b9d69bb8e856676bd1a4afc8062d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 13 May 2019 12:04:31 -0400 Subject: [PATCH] [libcalamares] Avoid warnings / errors on both gcc and clang - Clang 8 can detect that there is no need for a return if all previous paths already return. GCC 8 does not. Clang warns if the unreachable return is there, GCC errors out if it isn't. - Introduce a hack NOTREACHED that comments-out on Clang, and marks as unreachable (but still present) on GCC. - This might go away with an [[unreachable]] annotation or similar. --- CMakeLists.txt | 3 +++ src/libcalamares/geoip/Handler.cpp | 1 + src/libcalamares/partition/PartitionSize.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 843e8bc69..a4571efba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) ) string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" ) endforeach() + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='//'" ) # Third-party code where we don't care so much about compiler warnings # (because it's uncomfortable to patch) get different flags; use @@ -218,6 +219,8 @@ else() set( SUPPRESS_3RDPARTY_WARNINGS "" ) set( SUPPRESS_BOOST_WARNINGS "" ) + + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='__builtin_unreachable();'" ) endif() # Use mark_thirdparty_code() to reduce warnings from the compiler diff --git a/src/libcalamares/geoip/Handler.cpp b/src/libcalamares/geoip/Handler.cpp index 60404c2d6..192ab1a7c 100644 --- a/src/libcalamares/geoip/Handler.cpp +++ b/src/libcalamares/geoip/Handler.cpp @@ -113,6 +113,7 @@ create_interface( Handler::Type t, const QString& selector ) return nullptr; #endif } + NOTREACHED return nullptr; } static RegionZonePair diff --git a/src/libcalamares/partition/PartitionSize.cpp b/src/libcalamares/partition/PartitionSize.cpp index 8eb399585..750f75393 100644 --- a/src/libcalamares/partition/PartitionSize.cpp +++ b/src/libcalamares/partition/PartitionSize.cpp @@ -166,6 +166,7 @@ PartitionSize::toBytes() const case SizeUnit::GiB: return CalamaresUtils::GiBtoBytes( static_cast( value() ) ); } + NOTREACHED return -1; } bool @@ -186,6 +187,7 @@ PartitionSize::operator< ( const PartitionSize& other ) const case SizeUnit::GiB: return ( toBytes() < other.toBytes () ); } + NOTREACHED return false; } bool @@ -206,6 +208,7 @@ PartitionSize::operator> ( const PartitionSize& other ) const case SizeUnit::GiB: return ( toBytes() > other.toBytes () ); } + NOTREACHED return false; } bool @@ -226,6 +229,7 @@ PartitionSize::operator== ( const PartitionSize& other ) const case SizeUnit::GiB: return ( toBytes() == other.toBytes () ); } + NOTREACHED return false; } } // namespace Calamares