lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 15ca198 6/6: Define and use LMI_CLANG in addi


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 15ca198 6/6: Define and use LMI_CLANG in addition to LMI_GCC
Date: Fri, 16 Apr 2021 18:12:50 -0400 (EDT)

branch: master
commit 15ca198980237faba4319ff21f3ae51f190be579
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Define and use LMI_CLANG in addition to LMI_GCC
    
    This makes all compiler checks more consistent, as each of the supported
    compilers now has its own corresponding preprocessor symbol.
    
    No real changes.
---
 boost_regex.hpp                | 12 ++++++------
 bourn_cast_test.cpp            |  8 ++++----
 calendar_date_test.cpp         |  8 ++++----
 config.hpp                     | 21 ++++++++++++++-------
 expression_template_0_test.cpp |  4 ++--
 input_test.cpp                 |  8 ++++----
 numeric_io_test.cpp            |  8 ++++----
 ssize_lmi_test.cpp             |  8 ++++----
 8 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/boost_regex.hpp b/boost_regex.hpp
index c87e093..5c90b4c 100644
--- a/boost_regex.hpp
+++ b/boost_regex.hpp
@@ -24,7 +24,7 @@
 
 #include "config.hpp"
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored "-Wchar-subscripts"
 #   pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -32,7 +32,7 @@
 #   pragma clang diagnostic ignored "-Wkeyword-macro"
 #   pragma clang diagnostic ignored "-Wparentheses-equality"
 #   pragma clang diagnostic ignored "-Wregister"
-#elif defined __GNUC__
+#elif defined LMI_GCC
 #   pragma GCC diagnostic push
 #   if 7 <= __GNUC__
 #       pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
@@ -44,12 +44,12 @@
 #   pragma GCC diagnostic ignored "-Wshadow"
 #   pragma GCC diagnostic ignored "-Wswitch-enum"
 #   pragma GCC diagnostic ignored "-Wuseless-cast"
-#endif // defined __GNUC__
+#endif // defined LMI_GCC
 #include <boost/regex.hpp>
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#elif defined __GNUC__
+#elif defined LMI_GCC
 #   pragma GCC diagnostic pop
-#endif // defined __GNUC__
+#endif // defined LMI_GCC
 
 #endif // boost_regex_hpp
diff --git a/bourn_cast_test.cpp b/bourn_cast_test.cpp
index 30b8b31..cdd89fa 100644
--- a/bourn_cast_test.cpp
+++ b/bourn_cast_test.cpp
@@ -459,10 +459,10 @@ void test_m64_neighborhood()
     // unsigned integer is UB.
 
     unsigned long long int const ull_max = ull_traits::max();
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 #if defined __GNUC__
 #   pragma GCC diagnostic push
 #   pragma GCC diagnostic ignored "-Wfloat-conversion"
@@ -471,9 +471,9 @@ void test_m64_neighborhood()
 #if defined __GNUC__
 #   pragma GCC diagnostic pop
 #endif // defined __GNUC__
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#endif // defined __clang__
+#endif // defined LMI_CLANG
     LMI_TEST(f_ull_max == static_cast<float>(ull_max));
     // Suppressed because behavior is undefined:
     // LMI_TEST(ull_max == static_cast<unsigned long long int>(f_ull_max));
diff --git a/calendar_date_test.cpp b/calendar_date_test.cpp
index 798bfb8..9ad4d9a 100644
--- a/calendar_date_test.cpp
+++ b/calendar_date_test.cpp
@@ -115,14 +115,14 @@ void CalendarDateTest::TestFundamentals()
     LMI_TEST_EQUAL(gregorian_epoch(), date1);
 
     // Assign from self.
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored "-Wself-assign-overloaded"
-#endif // defined __clang__
+#endif // defined LMI_CLANG
     date1 = date1;
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#endif // defined __clang__
+#endif // defined LMI_CLANG
     LMI_TEST_EQUAL(gregorian_epoch(), date1);
 
     // Assign from jdn_t.
diff --git a/config.hpp b/config.hpp
index 1aa5108..e847c5e 100644
--- a/config.hpp
+++ b/config.hpp
@@ -108,14 +108,21 @@ namespace fs = boost::filesystem;
 //
 #include "platform_dependent.hpp"
 
-// Testing for the predefined __GNUC__ is not always the right thing
-// to do, as it is also defined by mostly gcc-compatible compilers
-// such as clang or (not currently supported) icc, so define a symbol
-// which is only defined for gcc itself, but not any others, to be
-// used where the difference between them matters.
-#if defined __GNUC__ && !defined __clang__
+// Both clang and gcc, as well as some other compilers, such as the
+// (currently unsupported) icc, predefine __GNUC__ to indicate that
+// they're mostly gcc-compatible, but we sometimes need to test for
+// the actual compiler used, e.g. when dealing with compiler-specific
+// warnings, so define symbols really identifying it that can be used
+// when the difference between clang and gcc matters.
+//
+// Note that this is consistent with what is done for LMI_MSC below.
+//
+// Order of tests is important here: real gcc must be tested last.
+#if defined __clang__
+#   define LMI_CLANG
+#elif defined __GNUC__
 #   define LMI_GCC
-#endif // defined __GNUC__ && !defined __clang__
+#endif // defined __GNUC__
 
 // It is impossible to compile lmi with g++ prior to version 3, though
 // old versions of gcc would be adequate for C translation units.
diff --git a/expression_template_0_test.cpp b/expression_template_0_test.cpp
index 94bae31..815bcd2 100644
--- a/expression_template_0_test.cpp
+++ b/expression_template_0_test.cpp
@@ -45,12 +45,12 @@
 #include "timer.hpp"
 
 #if defined USE_UBLAS
-#   if defined __clang__
+#   if defined LMI_CLANG
 #       pragma clang diagnostic push
 #       pragma clang diagnostic ignored "-Wdeprecated-copy"
 #   endif
 #   include <boost/numeric/ublas/vector.hpp>
-#   if defined __clang__
+#   if defined LMI_CLANG
 #       pragma clang diagnostic pop
 #   endif
 #endif // defined USE_UBLAS
diff --git a/input_test.cpp b/input_test.cpp
index 3c7ccef..50b84a9 100644
--- a/input_test.cpp
+++ b/input_test.cpp
@@ -159,10 +159,10 @@ void input_test::test_product_database()
 
     // Test query<enumerative type> with non-enumerative entities.
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored 
"-Wtautological-constant-out-of-range-compare"
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
     // This value corresponds to no enumerator, but C++ allows that.
     db.query_into(DB_ChildRiderMinAmt, a);
@@ -170,9 +170,9 @@ void input_test::test_product_database()
     auto const b {db.query<oenum_alb_or_anb>(DB_ChildRiderMinAmt)};
     LMI_TEST_EQUAL(25000, b);
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
     // Redundant template argument is okay.
     db.query_into<oenum_alb_or_anb>(DB_ChildRiderMinAmt, a);
diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index d4c68ed..4d577d2 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -29,16 +29,16 @@
 #include "test_tools.hpp"
 #include "timer.hpp"
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored "-Wsometimes-uninitialized"
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
 #include <boost/lexical_cast.hpp>
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
 #include <cmath>                        // exp()
 #include <limits>
diff --git a/ssize_lmi_test.cpp b/ssize_lmi_test.cpp
index 484ec35..a94fc6b 100644
--- a/ssize_lmi_test.cpp
+++ b/ssize_lmi_test.cpp
@@ -126,10 +126,10 @@ constexpr char f0c(T(&)[n])
     return bourn_cast<char>(n);
 }
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic push
 #   pragma clang diagnostic ignored "-Wbraced-scalar-init"
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
 // deduce int, return char; braced-init-list
 template<typename T, int n>
@@ -152,9 +152,9 @@ char f0f(T(&)[n])
     return {n}; // error: narrowing conversion of '128' from 'unsigned int'
 }
 
-#if defined __clang__
+#if defined LMI_CLANG
 #   pragma clang diagnostic pop
-#endif // defined __clang__
+#endif // defined LMI_CLANG
 
 // deduce auto, return char; braced-init-list
 // auto is deduced to int, not to std::size_t



reply via email to

[Prev in Thread] Current Thread [Next in Thread]