Skip to content

Commit

Permalink
Merge 47bd7ab into 4e532aa
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Sep 6, 2020
2 parents 4e532aa + 47bd7ab commit ed70b7d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
71 changes: 71 additions & 0 deletions include/internal/iutest_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@


// c++20 features

//! has concepts
#if !defined(IUTEST_HAS_CONCEPTS)
# if defined(__cpp_concepts) && __cpp_concepts >= 201907
# define IUTEST_HAS_CONCEPTS 1
Expand All @@ -111,6 +113,24 @@
# define IUTEST_HAS_CONCEPTS 0
#endif

//! has likely/unlikely attribute
#if !defined(IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY)
# if defined(__has_cpp_attribute)
# if __has_cpp_attribute(likely) >= 201803L && __has_cpp_attribute(unlikely) >= 201803L
# if defined(__GNUC__) && (__GNUC__ <= 9)
// gcc 9.X likely is experimental. can be used in switch~case, cannot be used in if statement
# define IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY 0
# else
# define IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY 1
# endif
# endif
# endif
#endif

#if !defined(IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY)
# define IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY 0
#endif

// c++17 features

//! inline variable
Expand Down Expand Up @@ -1190,6 +1210,30 @@
# define IUTEST_HAS_ATTRIBUTE 0
#endif

//! likely attribute
#if !defined(IUTEST_ATTRIBUTE_LIKELY_)
# if IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY
# define IUTEST_ATTRIBUTE_LIKELY_ [[likely]]
# else
# endif
#endif

#if !defined(IUTEST_ATTRIBUTE_LIKELY_)
# define IUTEST_ATTRIBUTE_LIKELY_
#endif

//! unlikely attribute
#if !defined(IUTEST_ATTRIBUTE_UNLIKELY_)
# if IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY
# define IUTEST_ATTRIBUTE_UNLIKELY_ [[unlikely]]
# else
# endif
#endif

#if !defined(IUTEST_ATTRIBUTE_UNLIKELY_)
# define IUTEST_ATTRIBUTE_UNLIKELY_
#endif

//! has deprecated attribute
#if !defined(IUTEST_HAS_ATTRIBUTE_DEPRECATED)
# if defined(__has_cpp_attribute)
Expand Down Expand Up @@ -1313,6 +1357,33 @@
#endif


// builtin

//! builtin except
#if !defined(IUTEST_HAS_BUILTIN_EXCEPT)
# define IUTEST_HAS_BUILTIN_EXCEPT 0
#endif

#if !defined(IUTEST_COND_LIKELY)
# if IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY
# define IUTEST_COND_LIKELY(cond) (cond) IUTEST_ATTRIBUTE_LIKELY_
# elif IUTEST_HAS_BUILTIN_EXCEPT
# define IUTEST_COND_LIKELY(cond) (cond)
# else
# define IUTEST_COND_LIKELY(cond) (cond)
# endif
#endif

#if !defined(IUTEST_COND_UNLIKELY)
# if IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY
# define IUTEST_COND_UNLIKELY(cond) (cond) IUTEST_ATTRIBUTE_UNLIKELY_
# elif IUTEST_HAS_BUILTIN_EXCEPT
# define IUTEST_COND_UNLIKELY(cond) (cond)
# else
# define IUTEST_COND_UNLIKELY(cond) (cond)
# endif
#endif

//! MemorySanitizer
#if !defined(IUTEST_HAS_MEMORY_SANITIZER)
# if defined(__has_feature)
Expand Down
4 changes: 2 additions & 2 deletions include/internal/iutest_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
#define IUTEST_TEST_BOOLEAN_(expression, text, actual, expected, on_failure) \
IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if( const ::iutest::AssertionResult iutest_ar = ::iutest::AssertionResult::Is(expression) ) \
; \
IUTEST_ATTRIBUTE_LIKELY_; \
else \
on_failure(::iutest::internal::GetBooleanAssertionFailureMessage( \
iutest_ar, text, #actual, #expected).c_str() )
Expand All @@ -423,7 +423,7 @@
* @internal
* @brief assert
*/
#define IUTEST_ASSERT_EXIT(cond) do { if( !(cond) ) { \
#define IUTEST_ASSERT_EXIT(cond) do { if IUTEST_COND_UNLIKELY( !(cond) ) { \
IUTEST_MESSAGE(#cond, ::iutest::TestPartResult::kFatalFailure); \
exit(1); \
} } while(::iutest::detail::AlwaysFalse())
Expand Down
2 changes: 2 additions & 0 deletions include/internal/iutest_option_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ inline void iuOptionMessage::ShowSpec()
IIUT_SHOW_MACRO(IUTEST_CPLUSPLUS);
IIUT_SHOW_MACRO(IUTEST_HAS_ANALYSIS_ASSUME);
IIUT_SHOW_MACRO(IUTEST_HAS_ATTRIBUTE);
IIUT_SHOW_MACRO(IUTEST_HAS_ATTRIBUTE_DEPRECATED);
IIUT_SHOW_MACRO(IUTEST_HAS_ATTRIBUTE_LIKELY_UNLIKELY);
IIUT_SHOW_MACRO(IUTEST_HAS_AUTO);
IIUT_SHOW_MACRO(IUTEST_HAS_CATCH_SEH_EXCEPTION_ASSERTION);
IIUT_SHOW_MACRO(IUTEST_HAS_CHAR16_T);
Expand Down

0 comments on commit ed70b7d

Please sign in to comment.