lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 327d53c 06/16: Conditionally suppress selecte


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 327d53c 06/16: Conditionally suppress selected x86_64-linux-gnu gcc-8 diagnostics
Date: Thu, 15 Nov 2018 17:37:03 -0500 (EST)

branch: master
commit 327d53c79588e57546362f4ceae52b335f371cf8
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Conditionally suppress selected x86_64-linux-gnu gcc-8 diagnostics
    
    It is appropriate to suppress certain '-Wformat' diagnostics for edge
    cases in a unit test of std::snprintf() where the compiler would warn
    of exactly the exotic case deliberately being tested.
---
 snprintf_test.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/snprintf_test.cpp b/snprintf_test.cpp
index 6f55f96..21eada9 100644
--- a/snprintf_test.cpp
+++ b/snprintf_test.cpp
@@ -43,12 +43,19 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL(4, len);
 
     // All tests in this group fail with the defective msvc rtl.
+#if defined __GNUC__
+#   pragma GCC diagnostic push
+#   pragma GCC diagnostic ignored "-Wformat-truncation"
+#endif // defined __GNUC__
     len = std::snprintf(buf, 3, "%4d", 1234);
     BOOST_TEST_EQUAL(4, len);
     // This test fails with borland C++ 5.5.1 .
     BOOST_TEST_EQUAL(std::string(buf, 9), std::string("12\0zzzzzz\0", 9));
 
     len = std::snprintf(buf, 4, "%4d", 1234);
+#if defined __GNUC__
+#   pragma GCC diagnostic pop
+#endif // defined __GNUC__
     BOOST_TEST_EQUAL(4, len);
     // This test fails with the defective msvc rtl and also
     // with borland C++ 5.5.1 .
@@ -59,11 +66,18 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL(std::string(buf, 9), std::string("1234\0zzzz\0", 9));
 
     long double z = 2.718281828459045L;
+#if defined __GNUC__
+#   pragma GCC diagnostic push
+#   pragma GCC diagnostic ignored "-Wformat-truncation"
+#endif // defined __GNUC__
     len = std::snprintf(buf, 5, "%.5Lf", z);
     BOOST_TEST_EQUAL(7, len);
     // This should truncate to 2.71, not round to 2.72 .
     BOOST_TEST_EQUAL(std::string(buf, 9), std::string("2.71\0zzzz\0", 9));
     len = std::snprintf(buf, 7, "%.5Lf", z);
+#if defined __GNUC__
+#   pragma GCC diagnostic pop
+#endif // defined __GNUC__
     BOOST_TEST_EQUAL(7, len);
     BOOST_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]