Skip to content

Commit 75ca3b9

Browse files
authored
Feature/compiler warnings (#22)
Many compiler warnings were added and converted to errors. Minor code clean up.
1 parent 9d249b5 commit 75ca3b9

File tree

11 files changed

+111
-43
lines changed

11 files changed

+111
-43
lines changed

include/cib/callback.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ namespace cib {
6767
CIB_CONSTEVAL callback() = default;
6868

6969
template<typename PrevFuncsType>
70-
CIB_CONSTEVAL callback(
70+
CIB_CONSTEVAL explicit callback(
7171
PrevFuncsType const & prev_funcs,
7272
func_ptr_t new_func
7373
)
7474
: funcs{}
7575
{
76-
for (int i = 0; i < prev_funcs.size(); i++) {
76+
for (unsigned int i = 0; i < prev_funcs.size(); i++) {
7777
funcs[i] = prev_funcs[i];
7878
}
7979

@@ -87,8 +87,6 @@ namespace cib {
8787
* to service builders based on a project's cib::config and cib::extend
8888
* declarations.
8989
*
90-
* @param func
91-
*
9290
* @return
9391
* A version of this callback builder with the addition of func.
9492
*

include/cib/config.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ namespace cib {
100100
* If predicate evaluates to true, then the configs will be added to the
101101
* configuration. Otherwise the configs contained in this conditional
102102
* will not be added.
103-
*
104-
* @param condition
105-
* @param configs
106103
*/
107104
template<typename Predicate, typename... Configs>
108105
[[nodiscard]] CIB_CONSTEVAL auto conditional(

include/cib/detail/conditional.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace cib::detail {
1616
CIB_CONSTEXPR static Condition condition{};
1717
detail::config<Configs...> body;
1818

19-
CIB_CONSTEVAL conditional(
19+
CIB_CONSTEVAL explicit conditional(
2020
Condition,
2121
Configs const & ... configs
2222
)
@@ -63,13 +63,13 @@ namespace cib::detail {
6363
template<typename MatchType>
6464
struct arg {
6565
template<typename Rhs>
66-
CIB_CONSTEVAL equality<arg<MatchType>, Rhs> operator==(Rhs const &) const {
66+
[[nodiscard]] CIB_CONSTEVAL equality<arg<MatchType>, Rhs> operator==(Rhs const &) const {
6767
return {};
6868
}
6969

7070
template<typename... Args>
7171
CIB_CONSTEVAL auto operator()(Args... args) const {
72-
return detail::fold_right(std::make_tuple(args...), detail::int_<0>, [=](auto elem, auto state){
72+
return detail::fold_right(std::make_tuple(args...), detail::int_<0>, [=](auto elem, [[maybe_unused]] auto state){
7373
using ElemType = typename std::remove_cv_t<std::remove_reference_t<decltype(elem)>>::value_type;
7474

7575
if constexpr (std::is_same_v<ElemType, MatchType>) {

include/cib/detail/config_details.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
namespace cib::detail {
1313
template<typename... ConfigTs>
1414
struct config : public detail::config_item {
15-
std::tuple<ConfigTs...> configsTuple;
15+
std::tuple<ConfigTs...> configs_tuple;
1616

17-
[[nodiscard]] CIB_CONSTEVAL config(
17+
CIB_CONSTEVAL explicit config(
1818
ConfigTs const & ... configs
1919
)
20-
: configsTuple{configs...}
20+
: configs_tuple{configs...}
2121
{
2222
// pass
2323
}
2424

2525
template<typename BuildersT, typename... Args>
2626
[[nodiscard]] CIB_CONSTEVAL auto init(
27-
BuildersT const & buildersTuple,
27+
BuildersT const & builders_tuple,
2828
Args const & ... args
2929
) const {
30-
return detail::fold_right(configsTuple, buildersTuple, [&](auto const & c, auto builders){
30+
return detail::fold_right(configs_tuple, builders_tuple, [&](auto const & c, auto builders){
3131
return c.init(builders, args...);
3232
});
3333
}
@@ -36,9 +36,9 @@ namespace cib::detail {
3636
[[nodiscard]] CIB_CONSTEVAL auto exports_tuple(
3737
Args const & ... args
3838
) const {
39-
return std::apply([&](auto const & ... configsPack){
40-
return std::tuple_cat(configsPack.exports_tuple(args...)...);
41-
}, configsTuple);
39+
return std::apply([&](auto const & ... configs_pack){
40+
return std::tuple_cat(configs_pack.exports_tuple(args...)...);
41+
}, configs_tuple);
4242
}
4343
};
4444
}

include/cib/detail/extend.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace cib::detail {
1515
struct extend : public config_item {
1616
std::tuple<Args...> args_tuple;
1717

18-
[[nodiscard]] CIB_CONSTEVAL extend(
18+
CIB_CONSTEVAL explicit extend(
1919
Args const & ... args
2020
)
2121
: args_tuple{args...}

include/cib/detail/meta.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace cib::detail {
1212
template<int value>
13-
CIB_CONSTEXPR auto int_ = std::integral_constant<int, value>{};
13+
CIB_CONSTEXPR static auto int_ = std::integral_constant<int, value>{};
1414

1515
template<typename Lhs, typename Rhs>
1616
CIB_CONSTEXPR static auto is_same_v =
@@ -34,22 +34,22 @@ namespace cib::detail {
3434
typename ValueType,
3535
typename CallableType>
3636
struct fold_helper {
37-
ValueType const & element;
38-
CallableType const & operation;
37+
ValueType const & element_;
38+
CallableType const & operation_;
3939

40-
[[nodiscard]] CIB_CONSTEXPR fold_helper(
40+
CIB_CONSTEXPR fold_helper(
4141
ValueType const & element,
4242
CallableType const & operation
4343
)
44-
: element{element}
45-
, operation{operation}
44+
: element_{element}
45+
, operation_{operation}
4646
{}
4747

4848
template<typename StateType>
4949
[[nodiscard]] CIB_CONSTEXPR inline auto operator+(
5050
StateType const & state
5151
) const {
52-
return operation(element, state);
52+
return operation_(element_, state);
5353
}
5454
};
5555

@@ -87,7 +87,6 @@ namespace cib::detail {
8787
/**
8888
* Perform an operation on each element of an integral sequence.
8989
*
90-
* @param sequence
9190
* @param operation
9291
* The operation to perform. Must be a callable that accepts a single parameter.
9392
*/
@@ -106,7 +105,6 @@ namespace cib::detail {
106105
* Perform an operation on each element of an integral sequence from 0 to
107106
* num_elements.
108107
*
109-
* @param num_elements
110108
* @param operation
111109
* The operation to perform. Must be a callable that accepts a single parameter.
112110
*/
@@ -125,7 +123,6 @@ namespace cib::detail {
125123
/**
126124
* Perform an operation on each element of a tuple.
127125
*
128-
* @param num_elements
129126
* @param operation
130127
* The operation to perform. Must be a callable that accepts a single parameter.
131128
*/

include/cib/detail/nexus_details.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ namespace cib {
2020

2121
template<typename Config, typename Tag>
2222
struct initialized {
23-
CIB_CONSTEXPR static auto value = detail::fold_right(initialized_builders_v<Config>, 0, [](auto b, auto retval){
24-
if constexpr (std::is_same_v<decltype(b.first), Tag>) {
25-
return b.second;
26-
} else {
27-
return retval;
28-
}
29-
});
23+
CIB_CONSTEXPR static auto value =
24+
detail::fold_right(initialized_builders_v<Config>, 0, [](auto b, [[maybe_unused]] auto retval){
25+
if constexpr (std::is_same_v<decltype(b.first), Tag>) {
26+
return b.second;
27+
} else {
28+
return retval;
29+
}
30+
});
3031
};
3132
}
3233

test/CMakeLists.txt

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,95 @@ add_executable(tests detail/meta.cpp builder_meta.cpp callback.cpp nexus.cpp)
88
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
99
target_compile_options(tests
1010
PRIVATE
11-
-ftemplate-backtrace-limit=0
12-
-ferror-limit=2
11+
-ferror-limit=8
12+
-Weverything
13+
-Wshadow-all
14+
-Warray-bounds-pointer-arithmetic
15+
16+
-Wfor-loop-analysis
17+
-Wgcc-compat
18+
-Wglobal-constructors
19+
-Wgnu
20+
-Wheader-hygiene
21+
-Widiomatic-parentheses
22+
-Wnewline-eof
23+
-Wimplicit
1324
)
1425

26+
EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
27+
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
28+
29+
if (${CLANG_VERSION_STRING} VERSION_GREATER 9.0.0)
30+
target_compile_options(tests
31+
PRIVATE
32+
-Wmisleading-indentation
33+
)
34+
endif()
35+
36+
if (${CLANG_VERSION_STRING} VERSION_GREATER 8.0.0)
37+
target_compile_options(tests
38+
PRIVATE
39+
# this complains about many cases in which ctad is supported and intended
40+
-Wno-ctad-maybe-unsupported
41+
)
42+
endif()
43+
44+
if (${CLANG_VERSION_STRING} VERSION_GREATER 7.0.0)
45+
target_compile_options(tests
46+
PRIVATE
47+
-Wextra-semi-stmt
48+
)
49+
endif()
1550
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
1651
target_compile_options(tests
1752
PRIVATE
18-
-ftemplate-backtrace-limit=0
19-
-fmax-errors=2
53+
-fmax-errors=8
54+
-Wshadow
55+
-Wmisleading-indentation
56+
57+
# this complains about many cases in which ctad is supported and intended
58+
-Wno-ctad-maybe-unsupported
2059
)
2160
endif()
2261

62+
63+
target_compile_options(tests
64+
PRIVATE
65+
-ftemplate-backtrace-limit=0
66+
-Werror
67+
-Wpedantic
68+
-Wall
69+
-Wextra
70+
-Wextra-semi
71+
-Wformat-security
72+
-Wextra-semi
73+
-Wfloat-conversion
74+
-Wignored-qualifiers
75+
-Wold-style-cast
76+
-Wunused
77+
-Weffc++
78+
79+
# not feasible to change tuple padding for now
80+
-Wno-padded
81+
82+
# clang complains about @example, which seems to be a valid tag
83+
-Wno-documentation-unknown-command
84+
85+
# clang complains about @tparam on a template type alias
86+
-Wno-documentation
87+
88+
# compatibility with anything less than C++17 is not a goal
89+
-Wno-c++98-compat-pedantic
90+
-Wno-c++98-compat
91+
-Wno-c++11-compat
92+
-Wno-c++14-compat
93+
)
94+
2395
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain Cib)
2496

97+
# ensure the catch2 headers do not produce warnings
98+
target_include_directories(tests SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/lib/Catch2/src/)
99+
25100
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/lib/Catch2/extras)
26101
include(CTest)
27102
include(Catch)

test/callback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,4 @@ TEST_CASE("callback with args with multiple extensions", "[callback]") {
193193
SECTION("built type is convertable to the interface type") {
194194
REQUIRE(built_is_convertable_to_interface<CallbackWithArgsWithMultipleExtensions::meta>(built_callback));
195195
}
196-
}
196+
}

test/detail/meta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ TEST_CASE("fold_right multi-element tuple", "[meta]") {
2424

2525
REQUIRE(cib::detail::fold_right(t, 0, sum) == 15);
2626
REQUIRE(cib::detail::fold_right(t, 5, sum) == 20);
27-
}
27+
}

0 commit comments

Comments
 (0)