lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 9c413e5 2/3: Enable '-Wuseless-cast'


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9c413e5 2/3: Enable '-Wuseless-cast'
Date: Fri, 22 Jun 2018 18:30:16 -0400 (EDT)

branch: master
commit 9c413e54b4a96937d6788579182541f738400e48
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Enable '-Wuseless-cast'
    
    Incidental notes on certain changes:
    * getopt.cpp: Apparent g++ defect.
    * numeric_io_test.cpp: Explicit casts make this unit test clearer.
    * workhorse.make: Specified all inhibited warnings for wx-dependent
      files (redundantly). Exempted 'md5.o' because it is third-party
      code, and 'currency_test.o' because the currency class will no
      doubt be revised before being put into production.
---
 boost_regex.hpp     |  1 +
 getopt.cpp          | 12 ++++++++++++
 numeric_io_test.cpp |  9 +++++++++
 pchfile_wx.hpp      |  1 +
 workhorse.make      | 16 ++++++++++++++--
 5 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/boost_regex.hpp b/boost_regex.hpp
index 3cc454c..4ac2724 100644
--- a/boost_regex.hpp
+++ b/boost_regex.hpp
@@ -29,6 +29,7 @@
 #   if 7 <= __GNUC__
 #       pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
 #       pragma GCC diagnostic ignored "-Wregister"
+#       pragma GCC diagnostic ignored "-Wuseless-cast"
 #   endif // 7 <= __GNUC__
 #   pragma GCC diagnostic ignored "-Wshadow"
 #endif // defined __GNUC__
diff --git a/getopt.cpp b/getopt.cpp
index 86ee462..9062c46 100644
--- a/getopt.cpp
+++ b/getopt.cpp
@@ -730,7 +730,19 @@ GetOpt::operator()()
 
   {
     int c = *nextchar++;
+#if defined __GNUC__
+#   pragma GCC diagnostic push
+#   pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif // defined __GNUC__
+    // i686-w64-mingw32-g++-7.3 flags this cast as "useless", but
+    // that seems to be a defect: the first argument is const, so
+    // the return value is also const. Perhaps the presence of C99's
+    // 'char* strchr(char const*, int);' prototype confuses g++, but
+    // it's still a defect.
     char* temp = const_cast<char*>(std::strchr(noptstring.c_str(), c));
+#if defined __GNUC__
+#   pragma GCC diagnostic pop
+#endif // defined __GNUC__
 
     // Increment 'optind' when we start to process its last character.
     if(*nextchar == 0)
diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index f10d7a7..2cf9d54 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -227,6 +227,11 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL( "Z ", numeric_io_cast<std::string>( "Z "));
     BOOST_TEST_EQUAL(" Z ", numeric_io_cast<std::string>(" Z "));
 
+#if defined __GNUC__
+#   pragma GCC diagnostic push
+#   pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif // defined __GNUC__
+
     test_interconvertibility((         char)(   1), "1", __FILE__, __LINE__);
     test_interconvertibility((         char)('\1'), "1", __FILE__, __LINE__);
 
@@ -283,6 +288,10 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL(numeric_io_cast<long 
double>("3.36210314311209350626e-4932"), std::numeric_limits<long 
double>::min());
 #endif // !defined LMI_MSVCRT
 
+#if defined __GNUC__
+#   pragma GCC diagnostic pop
+#endif // defined __GNUC__
+
     test_interconvertibility(std::string("  as  df  "), "  as  df  ", 
__FILE__, __LINE__);
     // The converse
     //   test_interconvertibility("  as  df  ", std::string("  as  df  "),...
diff --git a/pchfile_wx.hpp b/pchfile_wx.hpp
index 441a1ca..dbd7289 100644
--- a/pchfile_wx.hpp
+++ b/pchfile_wx.hpp
@@ -40,6 +40,7 @@
 #   pragma GCC diagnostic ignored "-Wdouble-promotion"
 #   pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #   pragma GCC diagnostic ignored "-Wsign-conversion"
+#   pragma GCC diagnostic ignored "-Wuseless-cast"
 #endif // defined __GNUC__
 
 #if defined LMI_COMPILER_USES_PCH && !defined LMI_IGNORE_PCH
diff --git a/workhorse.make b/workhorse.make
index 60c92ed..b3b927d 100644
--- a/workhorse.make
+++ b/workhorse.make
@@ -497,7 +497,7 @@ gcc_cxx_warnings := \
   -Wreorder \
   -Wstrict-null-sentinel \
   -Wsynth \
-  -Wno-useless-cast \
+  -Wuseless-cast \
 
 # Too many warnings on correct code, e.g. exact comparison to zero:
 #  -Wfloat-equal \
@@ -515,7 +515,18 @@ wx_dependent_objects :=
 gcc_common_extra_warnings := \
   -Wcast-qual \
 
-$(wx_dependent_objects): gcc_common_extra_warnings += -Wno-cast-qual
+$(wx_dependent_objects): gcc_common_extra_warnings += \
+  -Wno-cast-qual \
+  -Wno-double-promotion \
+  -Wno-format-nonliteral \
+  -Wno-sign-conversion \
+  -Wno-useless-cast \
+
+currency_test.o: gcc_common_extra_warnings += \
+  -Wno-useless-cast \
+
+md5.o: gcc_common_extra_warnings += \
+  -Wno-useless-cast \
 
 ifeq (safestdlib,$(findstring safestdlib,$(build_type)))
   ifeq (3.4.5,$(gcc_version))
@@ -540,6 +551,7 @@ $(boost_regex_objects): gcc_common_extra_warnings += \
   -Wno-register \
   -Wno-shadow \
   -Wno-unused-macros \
+  -Wno-useless-cast \
 
 boost_dependent_objects := \
   $(boost_regex_objects) \



reply via email to

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