Commit 77a2e332 authored by Nolan O'Brien's avatar Nolan O'Brien Committed by Facebook GitHub Bot

Fix -Wstring-conversion warnings

Summary:
clang is particular about not treating strings as booleans, but it offers an "out" by using `expr && "string"` specifically for the use cases of `assert` like ours

**Before**
```
assert(!"Should never happen!"); <-- clang warning: -Wstring-conversion
```

**After**
```
assert(false && "Should never happen!");  <-- no clang warning
```

Reviewed By: yfeldblum

Differential Revision: D33796849

fbshipit-source-id: bd48139d0db04d50572e9ada29da777551774f84
parent af1b432c
...@@ -328,8 +328,9 @@ inline exception_wrapper::exception_wrapper( ...@@ -328,8 +328,9 @@ inline exception_wrapper::exception_wrapper(
namespace exception_wrapper_detail { namespace exception_wrapper_detail {
template <class Ex> template <class Ex>
Ex&& dont_slice(Ex&& ex) { Ex&& dont_slice(Ex&& ex) {
assert(typeid(ex) == typeid(std::decay_t<Ex>) || assert(
!"Dynamic and static exception types don't match. Exception would " (typeid(ex) == typeid(std::decay_t<Ex>)) &&
"Dynamic and static exception types don't match. Exception would "
"be sliced when storing in exception_wrapper."); "be sliced when storing in exception_wrapper.");
return std::forward<Ex>(ex); return std::forward<Ex>(ex);
} }
......
...@@ -68,7 +68,7 @@ using FixedStringBase = FixedStringBase_<>; ...@@ -68,7 +68,7 @@ using FixedStringBase = FixedStringBase_<>;
// it's testing for fails. In this way, precondition violations are reported // it's testing for fails. In this way, precondition violations are reported
// at compile-time instead of at runtime. // at compile-time instead of at runtime.
[[noreturn]] inline void assertOutOfBounds() { [[noreturn]] inline void assertOutOfBounds() {
assert(!"Array index out of bounds in BasicFixedString"); assert(false && "Array index out of bounds in BasicFixedString");
throw_exception<std::out_of_range>( throw_exception<std::out_of_range>(
"Array index out of bounds in BasicFixedString"); "Array index out of bounds in BasicFixedString");
} }
...@@ -89,7 +89,9 @@ constexpr std::size_t checkOverflowIfDebug(std::size_t i, std::size_t size) { ...@@ -89,7 +89,9 @@ constexpr std::size_t checkOverflowIfDebug(std::size_t i, std::size_t size) {
// Intentionally NOT constexpr. See note above for assertOutOfBounds // Intentionally NOT constexpr. See note above for assertOutOfBounds
[[noreturn]] inline void assertNotNullTerminated() noexcept { [[noreturn]] inline void assertNotNullTerminated() noexcept {
assert(!"Non-null terminated string used to initialize a BasicFixedString"); assert(
false &&
"Non-null terminated string used to initialize a BasicFixedString");
std::terminate(); // Fail hard, fail fast. std::terminate(); // Fail hard, fail fast.
} }
......
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