[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);
- [lmi-commits] [lmi] master updated (0ec5f1b -> 9cc560d), Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master 88f799c 6/8: Avoid using gcc-specific warnings with clang,
Greg Chicares <=
- [lmi-commits] [lmi] master d126046 5/8: Disable clang -Wbraced-scalar-init in a test, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master 9cc560d 8/8: Fix defect introduced 20210303T1108Z: misalignment, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master 71238a3 4/8: Disable clang tautological constant compare warning in a test, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master 0dda3f5 2/8: Disable clang -Wself-assign-overloaded warning in date test, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master fc767f7 3/8: Include <cmath> to get std::rint() declaration, not <math.h>, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master 33a1270 1/8: Remove tests involving std::mem_fun, Greg Chicares, 2021/03/08
- [lmi-commits] [lmi] master f5d41a0 7/8: Replace raw string literals, Greg Chicares, 2021/03/08