lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 88f799c 6/8: Avoid using gcc-specific warning


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 88f799c 6/8: Avoid using gcc-specific warnings with clang
Date: Mon, 8 Mar 2021 11:19:47 -0500 (EST)

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

    Avoid using gcc-specific warnings with clang
    
    Because clang predefines __GNUC__ (being mostly compatible with gcc),
    pragmas inside "#if defined __GNUC__" are also used with clang. But
    because clang is not perfectly compatible with the recent gcc versions,
    it complains about unknown warnings.
    
    Fix this by explicitly checking for "gcc and not clang". A perhaps
    better alternative could be to predefine LMI_GCC symbol for the real gcc
    and LMI_GCC_OR_CLANG for the code which should be used with both
    compilers.
---
 numeric_io_test.cpp |  8 ++++----
 snprintf_test.cpp   | 16 ++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index cc5f96c..3a8dd80 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -227,10 +227,10 @@ int test_main(int, char*[])
     LMI_TEST_EQUAL( "Z ", numeric_io_cast<std::string>( "Z "));
     LMI_TEST_EQUAL(" Z ", numeric_io_cast<std::string>(" Z "));
 
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic push
 #   pragma GCC diagnostic ignored "-Wuseless-cast"
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
 
     test_interconvertibility(static_cast<         char>(   1), "1", __FILE__, 
__LINE__);
     test_interconvertibility(static_cast<         char>('\1'), "1", __FILE__, 
__LINE__);
@@ -288,9 +288,9 @@ int test_main(int, char*[])
     LMI_TEST_EQUAL(numeric_io_cast<long 
double>("3.36210314311209350626e-4932"), std::numeric_limits<long 
double>::min());
 #endif // !defined LMI_MSVCRT
 
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic pop
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
 
     test_interconvertibility(std::string("  as  df  "), "  as  df  ", 
__FILE__, __LINE__);
     // The converse
diff --git a/snprintf_test.cpp b/snprintf_test.cpp
index 464b173..927b53c 100644
--- a/snprintf_test.cpp
+++ b/snprintf_test.cpp
@@ -43,19 +43,19 @@ int test_main(int, char*[])
     LMI_TEST_EQUAL(4, len);
 
     // All tests in this group fail with the defective msvc rtl.
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic push
 #   pragma GCC diagnostic ignored "-Wformat-truncation"
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
     len = std::snprintf(buf, 3, "%4d", 1234);
     LMI_TEST_EQUAL(4, len);
     // This test fails with borland C++ 5.5.1 .
     LMI_TEST_EQUAL(std::string(buf, 9), std::string("12\0zzzzzz\0", 9));
 
     len = std::snprintf(buf, 4, "%4d", 1234);
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic pop
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
     LMI_TEST_EQUAL(4, len);
     // This test fails with the defective msvc rtl and also
     // with borland C++ 5.5.1 .
@@ -66,18 +66,18 @@ int test_main(int, char*[])
     LMI_TEST_EQUAL(std::string(buf, 9), std::string("1234\0zzzz\0", 9));
 
     long double z = 2.718281828459045L;
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic push
 #   pragma GCC diagnostic ignored "-Wformat-truncation"
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
     len = std::snprintf(buf, 5, "%.5Lf", z);
     LMI_TEST_EQUAL(7, len);
     // This should truncate to 2.71, not round to 2.72 .
     LMI_TEST_EQUAL(std::string(buf, 9), std::string("2.71\0zzzz\0", 9));
     len = std::snprintf(buf, 7, "%.5Lf", z);
-#if defined __GNUC__
+#if defined __GNUC__ && !defined __clang__
 #   pragma GCC diagnostic pop
-#endif // defined __GNUC__
+#endif // defined __GNUC__ && !defined __clang__
     LMI_TEST_EQUAL(7, len);
     LMI_TEST_EQUAL(std::string(buf, 9), std::string("2.7182\0zz\0", 9));
     len = std::snprintf(buf,       0, "%1.12Lf", z);



reply via email to

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