Skip to content

Commit 5e1834c

Browse files
Tigran GeghamyanTigran Geghamyan
authored andcommitted
Updated variant index tag definitions for compatibiliy with clang compiler
1 parent 7e3bce8 commit 5e1834c

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

include/nonstd/variant.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ struct index_tag_t {};
205205
template< std::size_t K >
206206
inline void index_tag ( index_tag_t<K> = index_tag_t<K>() ) { }
207207

208-
#define variant_index_tag_t(K) void(&)( nonstd::variants::detail::index_tag_t<K> )
209-
#define variant_index_tag(K) nonstd::variants::detail::index_tag<K>
208+
#define variant_index_tag_t(K) nonstd::variants::detail::index_tag_t<K>*
209+
#define variant_index_tag(K) nullptr
210210

211211
} // namespace detail
212212
} // namespace variants

template/variant.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ struct index_tag_t {};
197197
template< std::size_t K >
198198
inline void index_tag ( index_tag_t<K> = index_tag_t<K>() ) { }
199199

200-
#define variant_index_tag_t(K) void(&)( nonstd::variants::detail::index_tag_t<K> )
201-
#define variant_index_tag(K) nonstd::variants::detail::index_tag<K>
200+
#define variant_index_tag_t(K) nonstd::variants::detail::index_tag_t<K>*
201+
#define variant_index_tag(K) nullptr
202202

203203
} // namespace detail
204204
} // namespace variants

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang" )
5757
set( OPTIONS -Wall -Wextra -Wconversion -Wsign-conversion -Wno-missing-braces -fno-elide-constructors )
5858
set( DEFINITIONS ${DEFCMN} )
5959

60+
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0" )
61+
6062
# GNU: available -std flags depends on version
6163
if( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
6264
message( STATUS "Matched: GNU")

test/variant.t.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ const void * test_nullptr = variant_nullptr;
2828
// Note: variant_BETWEEN() is not be available when std::variant is used:
2929
#define variant_t_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
3030

31+
#ifndef variant_COMPILER_VERSION
32+
# define variant_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) )
33+
#endif
34+
35+
#ifndef variant_COMPILER_CLANG_VERSION
36+
# if defined(__clang__)
37+
# define variant_COMPILER_CLANG_VERSION variant_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
38+
# else
39+
# define variant_COMPILER_CLANG_VERSION 0
40+
# endif
41+
#endif
42+
43+
#ifndef variant_COMPILER_GNUC_VERSION
44+
# if defined(__GNUC__) && !defined(__clang__)
45+
# define variant_COMPILER_GNUC_VERSION variant_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
46+
# else
47+
# define variant_COMPILER_GNUC_VERSION 0
48+
# endif
49+
#endif
50+
3151
// The following tracer code originates as Oracle from Optional by
3252
// Andrzej Krzemienski, https://github.com/akrzemi1/Optional.
3353

@@ -519,7 +539,13 @@ CASE( "variant: Allows to move-construct from element (C++11)" )
519539

520540
CASE( "variant: Allows to convert-copy-construct from element" )
521541
{
522-
#if !( defined(_MSC_VER) && variant_t_BETWEEN(_MSC_VER, 1920, 1930 ) && variant_USES_STD_VARIANT )
542+
#if ( defined(_MSC_VER) && variant_t_BETWEEN(_MSC_VER, 1920, 1930 ) && variant_USES_STD_VARIANT )
543+
EXPECT( !!"variant: no convert-copy-construct from element with std::variant (VS2019/VC142/1920)" );
544+
#elif ( variant_USES_STD_VARIANT && variant_COMPILER_GNUC_VERSION >= 1010 )
545+
EXPECT( !!"variant: no convert-copy-construct from element with GCC 10.1 or later" );
546+
#elif ( variant_USES_STD_VARIANT && variant_COMPILER_CLANG_VERSION >= 1100 )
547+
EXPECT( !!"variant: no convert-copy-construct from element with Clang 11 or later" );
548+
#else
523549
int i = 7;
524550

525551
variant<double, std::string> var1( i );
@@ -530,23 +556,25 @@ CASE( "variant: Allows to convert-copy-construct from element" )
530556

531557
EXPECT( var2.index() == 0u );
532558
EXPECT( get<0>(var2) == lest::approx(7) );
533-
#else
534-
EXPECT( !!"variant: no convert-copy-construct from element with std::variant (VS2019/VC142/1920)" );
535559
#endif
536560
}
537561

538562
CASE( "variant: Allows to convert-move-construct from element (C++11)" )
539563
{
540564
#if variant_CPP11_OR_GREATER
541-
#if !( defined(_MSC_VER) && variant_t_BETWEEN(_MSC_VER, 1920, 1930 ) && variant_USES_STD_VARIANT )
565+
#if ( defined(_MSC_VER) && variant_t_BETWEEN(_MSC_VER, 1920, 1930 ) && variant_USES_STD_VARIANT )
566+
EXPECT( !!"variant: no convert-copy-construct from element with std::variant (VS2019/VC142/1920)" );
567+
#elif ( variant_USES_STD_VARIANT && variant_COMPILER_GNUC_VERSION >= 1010 )
568+
EXPECT( !!"variant: no convert-copy-construct from element with GCC 10.1 or later" );
569+
#elif ( variant_USES_STD_VARIANT && variant_COMPILER_CLANG_VERSION >= 1100 )
570+
EXPECT( !!"variant: no convert-copy-construct from element with Clang 11 or later" );
571+
#else
542572
struct Int { operator int() { return 7; } };
543573

544574
variant<double, std::string> var( Int{} );
545575

546576
EXPECT( var.index() == 0u );
547577
EXPECT( get<0>(var) == lest::approx(7) );
548-
#else
549-
EXPECT( !!"variant: no convert-copy-construct from element with std::variant (VS2019/VC142/1920)" );
550578
#endif
551579
#else
552580
EXPECT( !!"variant: move-construction is not available (no C++11)" );
@@ -1640,7 +1668,7 @@ namespace issue_31 {
16401668
CopyOnly( CopyOnly const & ) {}
16411669
CopyOnly & operator=( CopyOnly const & ) { return *this; }
16421670

1643-
#if variant_CPP11_OR_GREATER
1671+
#if variant_CPP11_OR_GREATER && !(variant_USES_STD_VARIANT && defined(_LIBCPP_VERSION))
16441672
CopyOnly( CopyOnly && ) = delete;
16451673
CopyOnly & operator=( CopyOnly && ) = delete;
16461674
#endif

0 commit comments

Comments
 (0)