Commit 02a4b200 authored by Erich Graham's avatar Erich Graham Committed by Facebook GitHub Bot

Fix Folly issues with -Wcovered-switch-default compiler flag

Summary:
When compiled with `-Wcovered-switch-default`, Folly fails to build because it adds `default` to switches which are already exhaustive. For C++ safety, these switches are intentionally including a default, so wrap them in a pragma block to indicate that and locally disable the warning.

Causes -fmodules import issues for upstream library in D30379442.

Still remaining issues with C++ definition: P445339268

Reviewed By: ispeters

Differential Revision: D30397871

fbshipit-source-id: adead9e01d0ba3b21c2e1446150cc6fed0f58602
parent 8be32da3
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
#include <folly/Expected.h> #include <folly/Expected.h>
#include <folly/FBString.h> #include <folly/FBString.h>
#include <folly/Likely.h> #include <folly/Likely.h>
#include <folly/Portability.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/Traits.h> #include <folly/Traits.h>
#include <folly/Unit.h> #include <folly/Unit.h>
...@@ -641,6 +642,8 @@ toAppend( ...@@ -641,6 +642,8 @@ toAppend(
1); // max trailing padding zeros 1); // max trailing padding zeros
char buffer[256]; char buffer[256];
StringBuilder builder(buffer, sizeof(buffer)); StringBuilder builder(buffer, sizeof(buffer));
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (mode) { switch (mode) {
case DoubleToStringConverter::SHORTEST: case DoubleToStringConverter::SHORTEST:
conv.ToShortest(value, &builder); conv.ToShortest(value, &builder);
...@@ -657,6 +660,7 @@ toAppend( ...@@ -657,6 +660,7 @@ toAppend(
conv.ToPrecision(value, int(numDigits), &builder); conv.ToPrecision(value, int(numDigits), &builder);
break; break;
} }
FOLLY_POP_WARNING
const size_t length = size_t(builder.position()); const size_t length = size_t(builder.position());
builder.Finalize(); builder.Finalize();
result->append(buffer, length); result->append(buffer, length);
......
...@@ -368,6 +368,8 @@ class fbstring_core { ...@@ -368,6 +368,8 @@ class fbstring_core {
FOLLY_NOINLINE FOLLY_NOINLINE
void reserve(size_t minCapacity, bool disableSSO = FBSTRING_DISABLE_SSO) { void reserve(size_t minCapacity, bool disableSSO = FBSTRING_DISABLE_SSO) {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (category()) { switch (category()) {
case Category::isSmall: case Category::isSmall:
reserveSmall(minCapacity, disableSSO); reserveSmall(minCapacity, disableSSO);
...@@ -381,6 +383,7 @@ class fbstring_core { ...@@ -381,6 +383,7 @@ class fbstring_core {
default: default:
folly::assume_unreachable(); folly::assume_unreachable();
} }
FOLLY_POP_WARNING
assert(capacity() >= minCapacity); assert(capacity() >= minCapacity);
} }
...@@ -408,6 +411,8 @@ class fbstring_core { ...@@ -408,6 +411,8 @@ class fbstring_core {
} }
size_t capacity() const { size_t capacity() const {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (category()) { switch (category()) {
case Category::isSmall: case Category::isSmall:
return maxSmallSize; return maxSmallSize;
...@@ -423,6 +428,7 @@ class fbstring_core { ...@@ -423,6 +428,7 @@ class fbstring_core {
default: default:
break; break;
} }
FOLLY_POP_WARNING
return ml_.capacity(); return ml_.capacity();
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <folly/Exception.h> #include <folly/Exception.h>
#include <folly/FormatTraits.h> #include <folly/FormatTraits.h>
#include <folly/MapUtil.h> #include <folly/MapUtil.h>
#include <folly/Portability.h>
#include <folly/Traits.h> #include <folly/Traits.h>
#include <folly/lang/Exception.h> #include <folly/lang/Exception.h>
#include <folly/lang/ToAscii.h> #include <folly/lang/ToAscii.h>
...@@ -313,6 +314,8 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { ...@@ -313,6 +314,8 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
int padChars = static_cast<int>(arg.width - val.size()); int padChars = static_cast<int>(arg.width - val.size());
memset(padBuf, fill, size_t(std::min(padBufSize, padChars))); memset(padBuf, fill, size_t(std::min(padBufSize, padChars)));
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (arg.align) { switch (arg.align) {
case FormatArg::Align::DEFAULT: case FormatArg::Align::DEFAULT:
case FormatArg::Align::LEFT: case FormatArg::Align::LEFT:
...@@ -331,6 +334,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) { ...@@ -331,6 +334,7 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb) {
abort(); abort();
break; break;
} }
FOLLY_POP_WARNING
} }
cb(val); cb(val);
...@@ -439,6 +443,8 @@ class FormatValue< ...@@ -439,6 +443,8 @@ class FormatValue<
sign = '-'; sign = '-';
} else { } else {
uval = static_cast<UT>(val_); uval = static_cast<UT>(val_);
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (arg.sign) { switch (arg.sign) {
case FormatArg::Sign::PLUS_OR_MINUS: case FormatArg::Sign::PLUS_OR_MINUS:
sign = '+'; sign = '+';
...@@ -453,6 +459,7 @@ class FormatValue< ...@@ -453,6 +459,7 @@ class FormatValue<
sign = '\0'; sign = '\0';
break; break;
} }
FOLLY_POP_WARNING
} }
} else { } else {
uval = static_cast<UT>(val_); uval = static_cast<UT>(val_);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/Format.h> #include <folly/Format.h>
#include <folly/Likely.h> #include <folly/Likely.h>
#include <folly/Portability.h>
#include <folly/detail/Iterators.h> #include <folly/detail/Iterators.h>
#include <folly/lang/Exception.h> #include <folly/lang/Exception.h>
...@@ -87,11 +88,13 @@ struct hash<::folly::dynamic> { ...@@ -87,11 +88,13 @@ struct hash<::folly::dynamic> {
} // namespace std } // namespace std
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/* clang-format off */
// This is a higher-order preprocessor macro to aid going from runtime // This is a higher-order preprocessor macro to aid going from runtime
// types to the compile time type system. // types to the compile time type system.
#define FB_DYNAMIC_APPLY(type, apply) \ #define FB_DYNAMIC_APPLY(type, apply) \
do { \ do { \
FOLLY_PUSH_WARNING FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default") \
switch ((type)) { \ switch ((type)) { \
case NULLT: \ case NULLT: \
apply(std::nullptr_t); \ apply(std::nullptr_t); \
...@@ -117,8 +120,9 @@ struct hash<::folly::dynamic> { ...@@ -117,8 +120,9 @@ struct hash<::folly::dynamic> {
default: \ default: \
abort(); \ abort(); \
} \ } \
FOLLY_POP_WARNING \
} while (0) } while (0)
/* clang-format on */
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
namespace folly { namespace folly {
...@@ -998,6 +1002,8 @@ FOLLY_DYNAMIC_DEC_TYPEINFO(dynamic::ObjectImpl, dynamic::OBJECT) ...@@ -998,6 +1002,8 @@ FOLLY_DYNAMIC_DEC_TYPEINFO(dynamic::ObjectImpl, dynamic::OBJECT)
template <class T> template <class T>
T dynamic::asImpl() const { T dynamic::asImpl() const {
FOLLY_PUSH_WARNING
FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
switch (type()) { switch (type()) {
case INT64: case INT64:
return to<T>(*get_nothrow<int64_t>()); return to<T>(*get_nothrow<int64_t>());
...@@ -1013,6 +1019,7 @@ T dynamic::asImpl() const { ...@@ -1013,6 +1019,7 @@ T dynamic::asImpl() const {
default: default:
throw_exception<TypeError>("int/double/bool/string", type()); throw_exception<TypeError>("int/double/bool/string", type());
} }
FOLLY_POP_WARNING
} }
// Return a T* to our type, or null if we're not that type. // Return a T* to our type, or null if we're not that type.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment