Skip to content

Commit 60913db

Browse files
committed
Simplify CTLL_CNTTP_COMPILER_CHECK and avoid -Wundef
The complicated single-line condition for defining this symbol generated several -Wundef warnings from clang 12 with libc++ under Linux, when __apple_build_version__ is not defined. Fixing them while keeping the original form of the condition would have made it even less readable, so rewrite it as a sequence of preprocessor tests instead for clarity.
1 parent ecae395 commit 60913db

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

include/ctll/utilities.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@
33

44
#include <type_traits>
55

6-
#define CTLL_CNTTP_COMPILER_CHECK (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L) || ((__cpp_nontype_template_args >= 201411L) && (__clang_major__ >= 12) && !__apple_build_version__))
6+
#if defined __cpp_nontype_template_parameter_class
7+
#define CTLL_CNTTP_COMPILER_CHECK 1
8+
#elif defined __cpp_nontype_template_args
9+
#if __cpp_nontype_template_args >= 201911L
10+
#define CTLL_CNTTP_COMPILER_CHECK 1
11+
#elif __cpp_nontype_template_args >= 201411L
12+
#if defined __clang_major__ && __clang_major__ >= 12
13+
#if !defined __apple_build_version__ || !__apple_build_version__
14+
#define CTLL_CNTTP_COMPILER_CHECK 1
15+
#endif
16+
#endif
17+
#endif
18+
#endif
19+
20+
#ifndef CTLL_CNTTP_COMPILER_CHECK
21+
#define CTLL_CNTTP_COMPILER_CHECK 0
22+
#endif
723

824
#ifdef _MSC_VER
925
#define CTLL_FORCE_INLINE __forceinline

single-header/ctre-unicode.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,23 @@ template <size_t N> fixed_string(fixed_string<N>) -> fixed_string<N>;
454454

455455
#include <type_traits>
456456

457-
#define CTLL_CNTTP_COMPILER_CHECK (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L) || ((__cpp_nontype_template_args >= 201411L) && (__clang_major__ >= 12) && !__apple_build_version__))
457+
#if defined __cpp_nontype_template_parameter_class
458+
#define CTLL_CNTTP_COMPILER_CHECK 1
459+
#elif defined __cpp_nontype_template_args
460+
#if __cpp_nontype_template_args >= 201911L
461+
#define CTLL_CNTTP_COMPILER_CHECK 1
462+
#elif __cpp_nontype_template_args >= 201411L
463+
#if defined __clang_major__ && __clang_major__ >= 12
464+
#if !defined __apple_build_version__ || !__apple_build_version__
465+
#define CTLL_CNTTP_COMPILER_CHECK 1
466+
#endif
467+
#endif
468+
#endif
469+
#endif
470+
471+
#ifndef CTLL_CNTTP_COMPILER_CHECK
472+
#define CTLL_CNTTP_COMPILER_CHECK 0
473+
#endif
458474

459475
#ifdef _MSC_VER
460476
#define CTLL_FORCE_INLINE __forceinline
@@ -1334,7 +1350,7 @@ struct pcre {
13341350
#ifndef CTRE__UTILITY__HPP
13351351
#define CTRE__UTILITY__HPP
13361352

1337-
#define CTRE_CNTTP_COMPILER_CHECK (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L) || ((__cpp_nontype_template_args >= 201411L) && (__clang_major__ >= 12) && !__apple_build_version__))
1353+
#define CTRE_CNTTP_COMPILER_CHECK CTLL_CNTTP_COMPILER_CHECK
13381354

13391355
#if __GNUC__ > 9
13401356
#if __has_cpp_attribute(likely)

single-header/ctre.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,23 @@ template <size_t N> fixed_string(fixed_string<N>) -> fixed_string<N>;
451451

452452
#include <type_traits>
453453

454-
#define CTLL_CNTTP_COMPILER_CHECK (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L) || ((__cpp_nontype_template_args >= 201411L) && (__clang_major__ >= 12) && !__apple_build_version__))
454+
#if defined __cpp_nontype_template_parameter_class
455+
#define CTLL_CNTTP_COMPILER_CHECK 1
456+
#elif defined __cpp_nontype_template_args
457+
#if __cpp_nontype_template_args >= 201911L
458+
#define CTLL_CNTTP_COMPILER_CHECK 1
459+
#elif __cpp_nontype_template_args >= 201411L
460+
#if defined __clang_major__ && __clang_major__ >= 12
461+
#if !defined __apple_build_version__ || !__apple_build_version__
462+
#define CTLL_CNTTP_COMPILER_CHECK 1
463+
#endif
464+
#endif
465+
#endif
466+
#endif
467+
468+
#ifndef CTLL_CNTTP_COMPILER_CHECK
469+
#define CTLL_CNTTP_COMPILER_CHECK 0
470+
#endif
455471

456472
#ifdef _MSC_VER
457473
#define CTLL_FORCE_INLINE __forceinline
@@ -1331,7 +1347,7 @@ struct pcre {
13311347
#ifndef CTRE__UTILITY__HPP
13321348
#define CTRE__UTILITY__HPP
13331349

1334-
#define CTRE_CNTTP_COMPILER_CHECK (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L) || ((__cpp_nontype_template_args >= 201411L) && (__clang_major__ >= 12) && !__apple_build_version__))
1350+
#define CTRE_CNTTP_COMPILER_CHECK CTLL_CNTTP_COMPILER_CHECK
13351351

13361352
#if __GNUC__ > 9
13371353
#if __has_cpp_attribute(likely)

0 commit comments

Comments
 (0)