Skip to content

Commit

Permalink
Initial use of _cpp_<*> macros for testing C++ features under Clang (#13
Browse files Browse the repository at this point in the history
).

- Tested locally using Clang6 from Visual Studio 2017 (with LLVM-vs2017 target integration).
  • Loading branch information
demianmnave committed Mar 28, 2018
1 parent eea719f commit d351844
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 77 deletions.
38 changes: 24 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,29 @@ elseif(MSVC)
list(APPEND CMAKE_CXX_FLAGS_DEBUG "/MTd")
list(APPEND CMAKE_CXX_FLAGS_RELEASE "/MT")

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.00)
list(APPEND CMAKE_CXX_FLAGS
/Zc:auto
/Zc:rvalueCast
/Zc:inline
/Zc:referenceBinding
/permissive-
)
endif()

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11)
list(APPEND CMAKE_CXX_FLAGS
/std:c++17
)

if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.00)
list(APPEND CMAKE_CXX_FLAGS
/Zc:auto
/Zc:rvalueCast
/Zc:inline
/Zc:referenceBinding
/permissive-
)
endif()

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.11)
list(APPEND CMAKE_CXX_FLAGS
/std:c++17
)
endif()
elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.00)
list(APPEND CMAKE_CXX_FLAGS
/std:c++17
)
endif()
endif()

elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -80,6 +89,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

# Enforce common compiler settings:
list(APPEND CMAKE_CXX_FLAGS "-fexceptions -std=c++1z")
message("yes")

elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")

Expand Down
110 changes: 47 additions & 63 deletions cml/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#if defined(__GNUC__) && (__GNUC__ > 4 \
|| ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)))
/* g++ support for C++11 features used by CML: */

/* N2439 move semantics for *this, used, for example, to efficiently return
* an expression node from a class method. Without this, a temporary is
Expand All @@ -33,29 +32,12 @@
/* This dummy qualifier is not needed for gcc: */
# define CML_DUMMY_TYPENAME

#elif defined(_MSC_VER)
/* VC++ support for C++11 features used by CML: */

# if _MSC_VER < 1900

/* VC++ (at least VS12) does not support move from *this, so no need to
* disambiguate:
*/
# define __CML_REF

/* VC++ (at least VS12) has brain-dead operator= overload resolution: */
# define CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS

/* VC++ 2013 cannot figure out default arguments returned as a template
* method without this qualifier:
#elif defined(__clang__)
/* Note: checking for Clang BEFORE checking for Visual Studio, since clang-cl
* defines _MSC_VER.
*/
# define CML_DUMMY_TYPENAME typename

/* No constexpr support: */
# define CML_CONSTEXPR inline

# else

# ifdef __cpp_ref_qualifiers
/* N2439 move semantics for *this, used, for example, to efficiently return
* an expression node from a class method. Without this, a temporary is
* returned instead:
Expand All @@ -66,83 +48,82 @@
* rvalue reference from this):
*/
# define __CML_REF &
# else
# define __CML_REF
# endif

/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

/* Constexpr support: */
# ifdef __cpp_constexpr
# define CML_CONSTEXPR constexpr

/* Not needed for other versions of VC++: */
# define CML_DUMMY_TYPENAME

# else
# define CML_CONSTEXPR inline
# endif

/* C++17 features: */
# if (_MSC_VER >= 1911) && (_MSVC_LANG >= 201703L)

/* Enable structured bindings: */
/* Structured bindings: */
# ifdef __cpp_structured_bindings
# define CML_HAS_STRUCTURED_BINDINGS

# endif

#elif defined(__clang__) && ((__clang_major__ >= 4) \
|| ((__clang_major__ >= 3) && (__clang_minor__ >= 5)))
/* clang support for C++11 features used by CML: */

/* N2439 move semantics for *this, used, for example, to efficiently return
* an expression node from a class method. Without this, a temporary is
* returned instead:
*/
# define CML_HAS_RVALUE_REFERENCE_FROM_THIS
/* Defaulted move constructor: */
# if ((__clang_major__ >= 4) \
|| ((__clang_major__ >= 3) && (__clang_minor__ >= 5))) \
|| (__apple_build_version__ >= 7000000)

/* Trailing method type for ref from *this (to disambiguate overloads using
* rvalue reference from this):
*/
# define __CML_REF &
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR
# endif

/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

/* Constexpr support: */
# define CML_CONSTEXPR constexpr

/* This dummy qualifier is not needed for Clang: */
# define CML_DUMMY_TYPENAME

/* C++17 features: */
# if __clang_major__ >= 4
#elif defined(_MSC_VER)

/* Enable structured bindings: */
# define CML_HAS_STRUCTURED_BINDINGS
# if _MSC_VER < 1900

# endif
/* VC++ (at least VS12) does not support move from *this, so no need to
* disambiguate:
*/
# define __CML_REF

/* VC++ (at least VS12) has brain-dead operator= overload resolution: */
# define CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS

/* VC++ 2013 cannot figure out default arguments returned as a template
* method without this qualifier:
*/
# define CML_DUMMY_TYPENAME typename

#elif defined(__apple_build_version__) && (__apple_build_version__ >= 7000000)
/* AppleClang support for C++11 features used by CML: */
/* No constexpr support: */
# define CML_CONSTEXPR inline

# else

/* N2439 move semantics for *this, used, for example, to efficiently return
* an expression node from a class method. Without this, a temporary is
* returned instead:
*/
# define CML_HAS_RVALUE_REFERENCE_FROM_THIS
# define CML_HAS_RVALUE_REFERENCE_FROM_THIS

/* Trailing method type for ref from *this (to disambiguate overloads using
* rvalue reference from this):
*/
# define __CML_REF &
# define __CML_REF &

/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

/* Constexpr support: */
# define CML_CONSTEXPR constexpr
# define CML_CONSTEXPR constexpr

/* This dummy qualifier is not needed for Clang: */
/* Not needed for other versions of VC++: */
# define CML_DUMMY_TYPENAME

/* C++17 features: */
# if __apple_build_version__ >= 9000000
# endif

# if (_MSC_VER >= 1911) && (_MSVC_LANG >= 201703L)

/* Enable structured bindings: */
# define CML_HAS_STRUCTURED_BINDINGS
Expand All @@ -158,6 +139,9 @@
/* Assume no rvalue reference from this: */
// # define CML_HAS_RVALUE_REFERENCE_FROM_THIS

/* Assume no structured bindings: */
// # define CML_HAS_STRUCTURED_BINDINGS

/* Assume no disambiguation needed: */
# define __CML_REF

Expand Down

0 comments on commit d351844

Please sign in to comment.