Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/compiler warnings #22

Merged
merged 10 commits into from
Apr 8, 2022
6 changes: 2 additions & 4 deletions include/cib/callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ namespace cib {
CIB_CONSTEVAL callback() = default;

template<typename PrevFuncsType>
CIB_CONSTEVAL callback(
CIB_CONSTEVAL explicit callback(
PrevFuncsType const & prev_funcs,
func_ptr_t new_func
)
: funcs{}
{
for (int i = 0; i < prev_funcs.size(); i++) {
for (unsigned int i = 0; i < prev_funcs.size(); i++) {
funcs[i] = prev_funcs[i];
}

Expand All @@ -87,8 +87,6 @@ namespace cib {
* to service builders based on a project's cib::config and cib::extend
* declarations.
*
* @param func
*
* @return
* A version of this callback builder with the addition of func.
*
Expand Down
3 changes: 0 additions & 3 deletions include/cib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ namespace cib {
* If predicate evaluates to true, then the configs will be added to the
* configuration. Otherwise the configs contained in this conditional
* will not be added.
*
* @param condition
* @param configs
*/
template<typename Predicate, typename... Configs>
[[nodiscard]] CIB_CONSTEVAL auto conditional(
Expand Down
6 changes: 3 additions & 3 deletions include/cib/detail/conditional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace cib::detail {
CIB_CONSTEXPR static Condition condition{};
detail::config<Configs...> body;

CIB_CONSTEVAL conditional(
CIB_CONSTEVAL explicit conditional(
Condition,
Configs const & ... configs
)
Expand Down Expand Up @@ -63,13 +63,13 @@ namespace cib::detail {
template<typename MatchType>
struct arg {
template<typename Rhs>
CIB_CONSTEVAL equality<arg<MatchType>, Rhs> operator==(Rhs const &) const {
[[nodiscard]] CIB_CONSTEVAL equality<arg<MatchType>, Rhs> operator==(Rhs const &) const {
return {};
}

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

if constexpr (std::is_same_v<ElemType, MatchType>) {
Expand Down
16 changes: 8 additions & 8 deletions include/cib/detail/config_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
namespace cib::detail {
template<typename... ConfigTs>
struct config : public detail::config_item {
std::tuple<ConfigTs...> configsTuple;
std::tuple<ConfigTs...> configs_tuple;

[[nodiscard]] CIB_CONSTEVAL config(
CIB_CONSTEVAL explicit config(
ConfigTs const & ... configs
)
: configsTuple{configs...}
: configs_tuple{configs...}
{
// pass
}

template<typename BuildersT, typename... Args>
[[nodiscard]] CIB_CONSTEVAL auto init(
BuildersT const & buildersTuple,
BuildersT const & builders_tuple,
Args const & ... args
) const {
return detail::fold_right(configsTuple, buildersTuple, [&](auto const & c, auto builders){
return detail::fold_right(configs_tuple, builders_tuple, [&](auto const & c, auto builders){
return c.init(builders, args...);
});
}
Expand All @@ -36,9 +36,9 @@ namespace cib::detail {
[[nodiscard]] CIB_CONSTEVAL auto exports_tuple(
Args const & ... args
) const {
return std::apply([&](auto const & ... configsPack){
return std::tuple_cat(configsPack.exports_tuple(args...)...);
}, configsTuple);
return std::apply([&](auto const & ... configs_pack){
return std::tuple_cat(configs_pack.exports_tuple(args...)...);
}, configs_tuple);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/cib/detail/extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace cib::detail {
struct extend : public config_item {
std::tuple<Args...> args_tuple;

[[nodiscard]] CIB_CONSTEVAL extend(
CIB_CONSTEVAL explicit extend(
Args const & ... args
)
: args_tuple{args...}
Expand Down
17 changes: 7 additions & 10 deletions include/cib/detail/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace cib::detail {
template<int value>
CIB_CONSTEXPR auto int_ = std::integral_constant<int, value>{};
CIB_CONSTEXPR static auto int_ = std::integral_constant<int, value>{};

template<typename Lhs, typename Rhs>
CIB_CONSTEXPR static auto is_same_v =
Expand All @@ -34,22 +34,22 @@ namespace cib::detail {
typename ValueType,
typename CallableType>
struct fold_helper {
ValueType const & element;
CallableType const & operation;
ValueType const & element_;
CallableType const & operation_;

[[nodiscard]] CIB_CONSTEXPR fold_helper(
CIB_CONSTEXPR fold_helper(
ValueType const & element,
CallableType const & operation
)
: element{element}
, operation{operation}
: element_{element}
, operation_{operation}
{}

template<typename StateType>
[[nodiscard]] CIB_CONSTEXPR inline auto operator+(
StateType const & state
) const {
return operation(element, state);
return operation_(element_, state);
}
};

Expand Down Expand Up @@ -87,7 +87,6 @@ namespace cib::detail {
/**
* Perform an operation on each element of an integral sequence.
*
* @param sequence
* @param operation
* The operation to perform. Must be a callable that accepts a single parameter.
*/
Expand All @@ -106,7 +105,6 @@ namespace cib::detail {
* Perform an operation on each element of an integral sequence from 0 to
* num_elements.
*
* @param num_elements
* @param operation
* The operation to perform. Must be a callable that accepts a single parameter.
*/
Expand All @@ -125,7 +123,6 @@ namespace cib::detail {
/**
* Perform an operation on each element of a tuple.
*
* @param num_elements
* @param operation
* The operation to perform. Must be a callable that accepts a single parameter.
*/
Expand Down
15 changes: 8 additions & 7 deletions include/cib/detail/nexus_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ namespace cib {

template<typename Config, typename Tag>
struct initialized {
CIB_CONSTEXPR static auto value = detail::fold_right(initialized_builders_v<Config>, 0, [](auto b, auto retval){
if constexpr (std::is_same_v<decltype(b.first), Tag>) {
return b.second;
} else {
return retval;
}
});
CIB_CONSTEXPR static auto value =
detail::fold_right(initialized_builders_v<Config>, 0, [](auto b, [[maybe_unused]] auto retval){
if constexpr (std::is_same_v<decltype(b.first), Tag>) {
return b.second;
} else {
return retval;
}
});
};
}

Expand Down
83 changes: 79 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,95 @@ add_executable(tests detail/meta.cpp builder_meta.cpp callback.cpp nexus.cpp)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(tests
PRIVATE
-ftemplate-backtrace-limit=0
-ferror-limit=2
-ferror-limit=8
-Weverything
-Wshadow-all
-Warray-bounds-pointer-arithmetic

-Wfor-loop-analysis
-Wgcc-compat
-Wglobal-constructors
-Wgnu
-Wheader-hygiene
-Widiomatic-parentheses
-Wnewline-eof
-Wimplicit
)

EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})

if (${CLANG_VERSION_STRING} VERSION_GREATER 9.0.0)
target_compile_options(tests
PRIVATE
-Wmisleading-indentation
)
endif()

if (${CLANG_VERSION_STRING} VERSION_GREATER 8.0.0)
target_compile_options(tests
PRIVATE
# this complains about many cases in which ctad is supported and intended
-Wno-ctad-maybe-unsupported
)
endif()

if (${CLANG_VERSION_STRING} VERSION_GREATER 7.0.0)
target_compile_options(tests
PRIVATE
-Wextra-semi-stmt
)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(tests
PRIVATE
-ftemplate-backtrace-limit=0
-fmax-errors=2
-fmax-errors=8
-Wshadow
-Wmisleading-indentation

# this complains about many cases in which ctad is supported and intended
-Wno-ctad-maybe-unsupported
)
endif()


target_compile_options(tests
PRIVATE
-ftemplate-backtrace-limit=0
-Werror
-Wpedantic
-Wall
-Wextra
-Wextra-semi
-Wformat-security
-Wextra-semi
-Wfloat-conversion
-Wignored-qualifiers
-Wold-style-cast
-Wunused
-Weffc++

# not feasible to change tuple padding for now
-Wno-padded

# clang complains about @example, which seems to be a valid tag
-Wno-documentation-unknown-command

# clang complains about @tparam on a template type alias
-Wno-documentation

# compatibility with anything less than C++17 is not a goal
-Wno-c++98-compat-pedantic
-Wno-c++98-compat
-Wno-c++11-compat
-Wno-c++14-compat
)

target_link_libraries(tests PRIVATE Catch2::Catch2WithMain Cib)

# ensure the catch2 headers do not produce warnings
target_include_directories(tests SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/lib/Catch2/src/)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/lib/Catch2/extras)
include(CTest)
include(Catch)
Expand Down
2 changes: 1 addition & 1 deletion test/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ TEST_CASE("callback with args with multiple extensions", "[callback]") {
SECTION("built type is convertable to the interface type") {
REQUIRE(built_is_convertable_to_interface<CallbackWithArgsWithMultipleExtensions::meta>(built_callback));
}
}
}
2 changes: 1 addition & 1 deletion test/detail/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ TEST_CASE("fold_right multi-element tuple", "[meta]") {

REQUIRE(cib::detail::fold_right(t, 0, sum) == 15);
REQUIRE(cib::detail::fold_right(t, 5, sum) == 20);
}
}
2 changes: 1 addition & 1 deletion test/nexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,4 @@ TEST_CASE("configuration with conditional features") {
nexus.service<TestCallback<2>>();
REQUIRE(is_callback_invoked<2>);
}
}
}