Skip to content

Commit 7f4f168

Browse files
authored
fix: treat warnings as errors in CI (#253)
Many users might compile the SDK using a "warnings as errors" flag. To support this use-case, update CI to compile the sdk with CMAKE_COMPILE_WARNING_AS_ERROR=TRUE. This commit also resolves existing warnings, with the exception of OpenSSL deprecation warnings which have been supressed using CMake generator expressions.
1 parent fa6662d commit 7f4f168

File tree

16 files changed

+121
-68
lines changed

16 files changed

+121
-68
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
BasedOnStyle: Chromium
33
IndentWidth: 4
44
QualifierAlignment: Right
5+
NamespaceIndentation: None
56
...

cmake/expected.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
77
cmake_policy(SET CMP0135 NEW)
88
endif ()
99

10+
set(EXPECTED_BUILD_TESTS OFF)
1011
FetchContent_Declare(tl-expected
1112
GIT_REPOSITORY https://github.com/TartanLlama/expected.git
1213
GIT_TAG 292eff8bd8ee230a7df1d6a1c00c4ea0eb2f0362
13-
)
14+
)
1415

1516
FetchContent_MakeAvailable(tl-expected)

libs/client-sdk/src/bindings/c/builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ LDClientConfigBuilder_Build(LDClientConfigBuilder b,
9393
LD_ASSERT_NOT_NULL(b);
9494
LD_ASSERT_NOT_NULL(out_config);
9595

96-
return launchdarkly::ConsumeBuilder<ConfigBuilder>(b, out_config);
96+
return launchdarkly::detail::ConsumeBuilder<ConfigBuilder>(b, out_config);
9797
}
9898

9999
LD_EXPORT(void)

libs/client-sdk/src/data_sources/streaming_data_source.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#include "streaming_data_source.hpp"
2+
3+
#include <launchdarkly/context_builder.hpp>
4+
#include <launchdarkly/detail/unreachable.hpp>
5+
#include <launchdarkly/encoding/base_64.hpp>
6+
#include <launchdarkly/network/http_requester.hpp>
7+
#include <launchdarkly/serialization/json_context.hpp>
8+
19
#include <boost/asio/any_io_executor.hpp>
210
#include <boost/asio/io_context.hpp>
311
#include <boost/asio/post.hpp>
@@ -6,13 +14,6 @@
614

715
#include <utility>
816

9-
#include "streaming_data_source.hpp"
10-
11-
#include <launchdarkly/context_builder.hpp>
12-
#include <launchdarkly/encoding/base_64.hpp>
13-
#include <launchdarkly/network/http_requester.hpp>
14-
#include <launchdarkly/serialization/json_context.hpp>
15-
1617
namespace launchdarkly::client_side::data_sources {
1718

1819
static char const* const kCouldNotParseEndpoint =
@@ -30,6 +31,7 @@ static char const* DataSourceErrorToString(launchdarkly::sse::Error error) {
3031
case sse::Error::ReadTimeout:
3132
return "read timeout reached";
3233
}
34+
launchdarkly::detail::unreachable();
3335
}
3436

3537
StreamingDataSource::StreamingDataSource(

libs/common/include/launchdarkly/attributes.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class Attributes final {
118118
: key_(std::move(key)),
119119
name_(std::move(name)),
120120
anonymous_(anonymous),
121-
custom_attributes_(std::move(attributes)),
122-
private_attributes_(std::move(private_attributes)) {}
121+
private_attributes_(std::move(private_attributes)),
122+
custom_attributes_(std::move(attributes)) {}
123123

124124
friend std::ostream& operator<<(std::ostream& out,
125125
Attributes const& attrs) {
@@ -142,9 +142,13 @@ class Attributes final {
142142
}
143143

144144
Attributes(Attributes const& context) = default;
145+
145146
Attributes(Attributes&& context) = default;
147+
146148
~Attributes() = default;
149+
147150
Attributes& operator=(Attributes const&) = default;
151+
148152
Attributes& operator=(Attributes&&) = default;
149153

150154
private:

libs/common/include/launchdarkly/detail/c_binding_helpers.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <tl/expected.hpp>
88

9-
namespace launchdarkly {
9+
namespace launchdarkly::detail {
1010
template <typename T, typename = void>
1111
struct has_result_type : std::false_type {};
1212

@@ -105,5 +105,5 @@ bool OptReturnReinterpretCast(std::optional<OptType>& opt,
105105

106106
#define LD_ASSERT_NOT_NULL(param) LD_ASSERT(param != nullptr)
107107

108-
} // namespace launchdarkly
108+
} // namespace launchdarkly::detail
109109
// NOLINTEND cppcoreguidelines-pro-type-reinterpret-cast
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace launchdarkly::detail {
2+
3+
// This may be replaced with a standard routine when C++23 is available.
4+
[[noreturn]] inline void unreachable() {
5+
// Uses compiler specific extensions if possible.
6+
// Even if no extension is used, undefined behavior is still raised by
7+
// an empty function body and the noreturn attribute.
8+
#if defined(__GNUC__) // GCC, Clang, ICC
9+
__builtin_unreachable();
10+
#elif defined(_MSC_VER) // MSVC
11+
__assume(false);
12+
#endif
13+
}
14+
} // namespace launchdarkly::detail

libs/common/include/launchdarkly/value.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Value final {
119119
using iterator_category = std::forward_iterator_tag;
120120
using difference_type = std::ptrdiff_t;
121121

122-
using value_type = std::pair<const std::string, Value>;
122+
using value_type = std::pair<std::string const, Value>;
123123
using pointer = value_type const*;
124124
using reference = value_type const&;
125125

@@ -374,7 +374,7 @@ class Value final {
374374
static Value const& Null();
375375

376376
friend std::ostream& operator<<(std::ostream& out, Value const& value) {
377-
switch (value.type_) {
377+
switch (value.Type()) {
378378
case Type::kNull:
379379
out << "null()";
380380
break;
@@ -409,16 +409,17 @@ class Value final {
409409
operator int() const { return AsInt(); }
410410

411411
private:
412-
std::variant<bool, double, std::string, Array, Object> storage_;
413-
enum Type type_;
412+
struct null_type {};
413+
414+
std::variant<null_type, bool, double, std::string, Array, Object> storage_;
414415

415416
// Empty constants used when accessing the wrong type.
416417
// These are not inline static const because of this bug:
417418
// https://developercommunity.visualstudio.com/t/inline-static-destructors-are-called-multiple-time/1157794
418-
static const std::string empty_string_;
419-
static const Array empty_vector_;
420-
static const Object empty_map_;
421-
static const Value null_value_;
419+
static std::string const empty_string_;
420+
static Array const empty_vector_;
421+
static Object const empty_map_;
422+
static Value const null_value_;
422423
};
423424

424425
bool operator==(Value const& lhs, Value const& rhs);

libs/common/src/attribute_reference.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ AttributeReference::AttributeReference(char const* ref_str)
229229
std::string AttributeReference::PathToStringReference(
230230
std::vector<std::string_view> path) {
231231
// Approximate size to reduce resizes.
232-
auto size = std::accumulate(path.begin(), path.end(), 0,
233-
[](auto sum, auto const& component) {
234-
return sum + component.size() + 1;
235-
});
232+
std::size_t size =
233+
std::accumulate(path.begin(), path.end(), std::size_t{0},
234+
[](std::size_t sum, auto const& component) {
235+
return sum + component.size() + 1;
236+
});
236237

237238
std::string redaction_name;
238239
redaction_name.reserve(size);

libs/common/src/bindings/c/data/evaluation_detail.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define FROM_REASON(ptr) (reinterpret_cast<LDEvalReason>(ptr));
1212

1313
using namespace launchdarkly;
14+
using namespace launchdarkly::detail;
1415

1516
LD_EXPORT(void)
1617
LDEvalDetail_Free(LDEvalDetail detail) {

0 commit comments

Comments
 (0)