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