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

std::is_same_v needs a compile config selector #1757

Closed
jl opened this issue Sep 18, 2019 · 1 comment
Closed

std::is_same_v needs a compile config selector #1757

jl opened this issue Sep 18, 2019 · 1 comment

Comments

@jl
Copy link

jl commented Sep 18, 2019

Describe the bug
Some compilers will appear to support C++17 but not support std::is_same_v properly, however, unlike other C++17 features with have a compile flag such as CATCH_CONFIG_NO_CPP17_BYTE there isn't an analogous one for std::is_same_v.

Expected behavior
User of catch should be able to #define CATCH_CONFIG_NO_CPP17_IS_SAME_V in a broken compiler and have catch work.

Reproduction steps
Compile a project with clang 8.0.0, observe the following error:

catch.hpp:686:10: error: no template named 'is_same_v' in namespace 'std'

cmake flags used:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

Platform information:

  • OS: 64-bit linux
  • Compiler+version: clang 8.0.0
  • Catch version: v2.9.2
  • Cmake version: 3.12

** Proposed patch (to single header)

diff --git a/catch.hpp b/catch.hpp
--- a/catch.hpp
+++ b/catch.hpp
@@ -311,6 +311,14 @@ namespace Catch {
 #  endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
 #endif // __has_include

+////////////////////////////////////////////////////////////////////////////////
+// Check if is_same_v is available and usable
+#if defined(__has_include)
+#  if __has_include(<type_traits>) && defined(CATCH_CPP17_OR_GREATER)
+#    define CATCH_INTERNAL_CONFIG_CPP17_IS_SAME_V
+#  endif // __has_include(<type_traits>) && defined(CATCH_CPP17_OR_GREATER)
+#endif // __has_include
+
 ////////////////////////////////////////////////////////////////////////////////
 // Check if variant is available and usable
 #if defined(__has_include)
@@ -369,6 +377,10 @@ namespace Catch {
 #  define CATCH_CONFIG_CPP17_BYTE
 #endif

+#if defined(CATCH_INTERNAL_CONFIG_CPP17_IS_SAME_V) && !defined(CATCH_CONFIG_NO_CPP17_IS_SAME_V) && !defined(CATCH_CONFIG_CPP17_IS_SAME_V)                               
+#  define CATCH_CONFIG_CPP17_IS_SAME_V
+#endif
+
 #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
 #  define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
 #endif
@@ -677,7 +689,7 @@ inline auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noex                                                                     

 namespace Catch{

-#ifdef CATCH_CPP17_OR_GREATER
+#if defined(CATCH_CONFIG_CPP17_IS_SAME_V)
        template <typename...>
        inline constexpr auto is_unique = std::true_type{};
@horenmar
Copy link
Member

Since the trait that uses it is no longer in use, I just removed the use completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants