Skip to content

Commit

Permalink
Fix #100 - TTS doesn't generate -Wshadow warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou authored Oct 24, 2024
1 parent 7c8ee2a commit 0310dd0
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 74 deletions.
4 changes: 2 additions & 2 deletions cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
target_compile_options( tts_test INTERFACE /W3 /EHsc )
else()
target_compile_options( tts_test INTERFACE -Werror -Wall -Wextra -Wunused-variable -Wdocumentation)
target_compile_options( tts_test INTERFACE -Werror -Wall -Wshadow -Wextra -Wunused-variable -Wdocumentation)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options( tts_test INTERFACE /W3 /EHsc /Zc:preprocessor)
else()
target_compile_options( tts_test INTERFACE -Werror -Wall -Wextra -Wunused-variable)
target_compile_options( tts_test INTERFACE -Werror -Wall -Wshadow -Wextra -Wunused-variable)
endif()

target_include_directories( tts_test INTERFACE
Expand Down
8 changes: 4 additions & 4 deletions include/tts/test/basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
#define TTS_EXPECT_REQUIRED(EXPR) TTS_EXPECT_IMPL((EXPR),TTS_FATAL)

#define TTS_EXPECT_IMPL(EXPR,FAILURE) \
[&](auto&& expr) \
[&](auto&& local_tts_expr) \
{ \
if( expr ) \
if( local_tts_expr ) \
{ \
::tts::global_runtime.pass(); return ::tts::detail::logger{false}; \
} \
Expand Down Expand Up @@ -97,9 +97,9 @@
#define TTS_EXPECT_NOT_REQUIRED(EXPR) TTS_EXPECT_NOT_IMPL(EXPR,TTS_FATAL)

#define TTS_EXPECT_NOT_IMPL(EXPR,FAILURE) \
[&](auto&& expr) \
[&](auto&& local_tts_expr) \
{ \
if( !expr ) \
if( !local_tts_expr ) \
{ \
::tts::global_runtime.pass(); return ::tts::detail::logger{false}; \
} \
Expand Down
39 changes: 20 additions & 19 deletions include/tts/test/precision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <tts/engine/logger.hpp>

#define TTS_PRECISION_IMPL(LHS, RHS, N, UNIT, FUNC, PREC,FAILURE) \
[&](auto lhs, auto rhs) \
[&](auto local_tts_lhs, auto local_tts_rhs) \
{ \
auto r = FUNC (lhs,rhs); \
auto r = FUNC (local_tts_lhs,local_tts_rhs); \
\
if(r <= N) \
{ \
Expand All @@ -26,7 +26,8 @@
{ \
FAILURE ( "Expected: " << TTS_STRING(LHS) << " == " << TTS_STRING(RHS) \
<< " but " \
<< ::tts::as_string(lhs) << " == " << ::tts::as_string(rhs) \
<< ::tts::as_string(local_tts_lhs) \
<< " == " << ::tts::as_string(local_tts_rhs) \
<< " within " << std::setprecision(PREC) << std::fixed \
<< r << std::defaultfloat \
<< " " << UNIT << " when " \
Expand Down Expand Up @@ -143,22 +144,22 @@
#define TTS_ULP_EQUAL(L,R,N,...) TTS_PRECISION(L,R,N,"ULP" , ::tts::ulp_distance , 2, __VA_ARGS__ )


#define TTS_DO_IEEE_EQUAL_IMPL(LHS, RHS, FAILURE) \
[&](auto lhs, auto rhs) \
{ \
if(::tts::is_ieee_equal(lhs,rhs)) \
{ \
::tts::global_runtime.pass(); return ::tts::detail::logger{false}; \
} \
else \
{ \
FAILURE ( "Expected: " << TTS_STRING(LHS) << " == " << TTS_STRING(RHS) \
<< " but " \
<< ::tts::as_string(lhs) << " != " << ::tts::as_string(rhs) \
); \
return ::tts::detail::logger{}; \
} \
}(LHS,RHS) \
#define TTS_DO_IEEE_EQUAL_IMPL(LHS, RHS, FAILURE) \
[&](auto local_tts_lhs, auto local_tts_rhs) \
{ \
if(::tts::is_ieee_equal(local_tts_lhs,local_tts_rhs)) \
{ \
::tts::global_runtime.pass(); return ::tts::detail::logger{false}; \
} \
else \
{ \
FAILURE ( "Expected: " << TTS_STRING(LHS) << " == " << TTS_STRING(RHS) \
<< " but " \
<< ::tts::as_string(local_tts_lhs) << " != " << ::tts::as_string(local_tts_rhs) \
); \
return ::tts::detail::logger{}; \
} \
}(LHS,RHS) \
/**/

#define TTS_DO_IEEE_EQUAL(L,R,...) TTS_DO_IEEE_EQUAL_ ## __VA_ARGS__ (L,R)
Expand Down
13 changes: 7 additions & 6 deletions include/tts/test/relation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#include <tts/test/info.hpp>

#define TTS_RELATION_BASE(A, B, OP, T, F, FAILURE) \
if( ::tts::detail::OP(a,b) ) \
if( ::tts::detail::OP(local_tts_a,local_tts_b) ) \
{ \
::tts::global_runtime.pass(); return ::tts::detail::logger{false}; \
} \
else \
{ \
FAILURE ( "Expression: " << TTS_STRING(A) << " " T " " << TTS_STRING(B) \
<< " is false because: " << ::tts::as_string(a) << " " F " " << ::tts::as_string(b) \
<< " is false because: " << ::tts::as_string(local_tts_a) \
<< " " F " " << ::tts::as_string(local_tts_b) \
); \
return ::tts::detail::logger{}; \
} \
Expand Down Expand Up @@ -49,7 +50,7 @@ else
#define TTS_RELATION_REQUIRED(A, B, OP, T, F) TTS_RELATION_IMPL(A,B,OP,T,F,TTS_FATAL)

#define TTS_RELATION_IMPL(A, B, OP, T, F, FAILURE) \
[&](auto&& a, auto&& b) \
[&](auto&& local_tts_a, auto&& local_tts_b) \
{ \
TTS_RELATION_BASE(A, B, OP, T, F, FAILURE) \
}(A,B) \
Expand Down Expand Up @@ -440,10 +441,10 @@ ::tts::detail::logger{::tts::global_logger_status}
#define TTS_TYPED_RELATION_REQUIRED(A, B, OP, T, F) TTS_TYPED_RELATION_IMPL(A,B,OP,T,F,TTS_FATAL)

#define TTS_TYPED_RELATION_IMPL(A, B, OP, T, F, FAILURE) \
[&](auto&& a, auto&& b) \
[&](auto&& local_tts_a, auto&& local_tts_b) \
{ \
using type_a = std::remove_cvref_t<decltype(a)>; \
using type_b = std::remove_cvref_t<decltype(b)>; \
using type_a = std::remove_cvref_t<decltype(local_tts_a)>; \
using type_b = std::remove_cvref_t<decltype(local_tts_b)>; \
\
if ( !tts::same_as<type_a, type_b> ) \
{ \
Expand Down
14 changes: 7 additions & 7 deletions include/tts/test/sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ namespace tts::detail
}

#define TTS_ALL_IMPL(SEQ1,SEQ2,OP,N,UNIT,FAILURE) \
[](auto const& a, auto const& b) \
[](auto const& local_tts_a, auto const& local_tts_b) \
{ \
if( std::size(b) != std::size(a) ) \
if( std::size(local_tts_b) != std::size(local_tts_a) ) \
{ \
FAILURE ( "Expected: " << TTS_STRING(SEQ1) << " == " << TTS_STRING(SEQ2) \
<< " but sizes does not match: " \
<< "size(" TTS_STRING(SEQ1) ") = " << std::size(a) \
<< " while size(" TTS_STRING(SEQ2) ") = " << std::size(b) \
<< "size(" TTS_STRING(SEQ1) ") = " << std::size(local_tts_a) \
<< " while size(" TTS_STRING(SEQ2) ") = " << std::size(local_tts_b) \
); \
return ::tts::detail::logger{}; \
} \
\
auto ba = std::begin(a); \
auto bb = std::begin(b); \
auto ea = std::end(a); \
auto ba = std::begin(local_tts_a); \
auto bb = std::begin(local_tts_b); \
auto ea = std::end(local_tts_a); \
\
std::vector < ::tts::detail::failure< std::remove_cvref_t<decltype(*ba)> \
, std::remove_cvref_t<decltype(*bb)> \
Expand Down
6 changes: 6 additions & 0 deletions include/tts/test/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
/**/

#define TTS_EXPECT_COMPILES_IMPL(EXPR, ...) \
TTS_DISABLE_WARNING_PUSH \
TTS_DISABLE_WARNING_SHADOW \
[&]( TTS_ARG(__VA_ARGS__) ) \
{ \
if constexpr( requires TTS_REMOVE_PARENS(EXPR) ) \
Expand All @@ -120,6 +122,7 @@
); \
return ::tts::detail::logger{}; \
} \
TTS_DISABLE_WARNING_POP \
}(__VA_ARGS__) \
/**/

Expand Down Expand Up @@ -154,6 +157,8 @@
#endif

#define TTS_EXPECT_NOT_COMPILES_IMPL(EXPR, ...) \
TTS_DISABLE_WARNING_PUSH \
TTS_DISABLE_WARNING_SHADOW \
[&]( TTS_ARG(__VA_ARGS__) ) \
{ \
if constexpr( !(requires TTS_REMOVE_PARENS(EXPR)) ) \
Expand All @@ -165,6 +170,7 @@
TTS_FAIL("Expression: " << TTS_STRING(TTS_REMOVE_PARENS(EXPR)) << " compiles unexpectedly." ); \
return ::tts::detail::logger{}; \
} \
TTS_DISABLE_WARNING_POP \
}(__VA_ARGS__) \
/**/

Expand Down
6 changes: 6 additions & 0 deletions include/tts/test/when.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ namespace tts::detail
**/
//======================================================================================================================
#define TTS_WHEN(STORY) \
TTS_DISABLE_WARNING_PUSH \
TTS_DISABLE_WARNING_SHADOW \
std::cout << "[^] - For: " << ::tts::detail::current_test << "\n"; \
std::cout << "When : " << STORY << std::endl; \
for(int tts_section = 0, tts_count = 1; tts_section < tts_count; tts_count -= 0==tts_section++) \
for( tts::detail::only_once tts_only_once_setup{}; tts_only_once_setup; ) \
TTS_DISABLE_WARNING_POP \
/**/

#define TTS_AND_THEN_IMPL(TTS_LOCAL_ID, ...) \
TTS_DISABLE_WARNING_PUSH \
TTS_DISABLE_WARNING_SHADOW \
static int TTS_LOCAL_ID = 0; \
std::ostringstream TTS_CAT(desc_,TTS_LOCAL_ID); \
if(::tts::detail::section_guard(TTS_LOCAL_ID, tts_section, tts_count ) \
Expand All @@ -94,6 +99,7 @@ namespace tts::detail
) \
for(int tts_section = 0, tts_count = 1; tts_section < tts_count; tts_count -= 0==tts_section++ ) \
for(tts::detail::only_once tts__only_once_section{}; tts__only_once_section; ) \
TTS_DISABLE_WARNING_POP \
/**/

//======================================================================================================================
Expand Down
Loading

0 comments on commit 0310dd0

Please sign in to comment.