lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 4e5b0c9f 5/6: Enable '-Wcomma' for clang


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 4e5b0c9f 5/6: Enable '-Wcomma' for clang
Date: Sun, 10 Jul 2022 12:07:57 -0400 (EDT)

branch: master
commit 4e5b0c9fe45adbf4936b9a40260c527b501d6640
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Enable '-Wcomma' for clang
    
    * compiler_clang_warnings.make: Enable this warning.
    * ledger.cpp: Rewrite the only line of lmi code that triggered this
    warning. It's better to avoid the archaic C style.
    * getopt.cpp: Exempt one line with a pragma.
    * zero.hpp: Likewise.
    
    The warning was stylistically legitimate for just one line of lmi code.
    For alien code, only two lines triggered it, so it's better to write
    two pragmata and keep the warning enabled.
---
 compiler_clang_warnings.make | 5 +----
 getopt.cpp                   | 8 ++++++++
 ledger.cpp                   | 3 ++-
 zero.hpp                     | 8 ++++++++
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/compiler_clang_warnings.make b/compiler_clang_warnings.make
index 722185b2..8a8e171a 100644
--- a/compiler_clang_warnings.make
+++ b/compiler_clang_warnings.make
@@ -50,11 +50,9 @@ clang_c_warnings := \
 #
 # -W++20-compat: backward compatibility not desirable
 # -W++98-compat-pedantic: backward compatibility not desirable
-### [triple '#' marks warnings requiring investigation]
-###  -Wcomma
 # -Wcovered-switch-default: better to leave "default:" in place
 # -Wdate-time: only for "bit-wise-identical reproducible compilations"
-###  -Wdeprecated-copy-with-dtor
+###  -Wdeprecated-copy-with-dtor [pending review]
 # -Wdocumentation: warns about comments
 # -Wdocumentation-html: warns about comments
 # -Wdocumentation-unknown-command: warns about comments
@@ -82,7 +80,6 @@ clang_cxx_warnings := \
   $(clang_common_warnings) \
   -Wno-c++20-compat \
   -Wno-c++98-compat-pedantic \
-  -Wno-comma \
   -Wno-covered-switch-default \
   -Wno-date-time \
   -Wno-deprecated-copy-with-dtor \
diff --git a/getopt.cpp b/getopt.cpp
index 83ee66bc..c0c6e8b8 100644
--- a/getopt.cpp
+++ b/getopt.cpp
@@ -504,7 +504,15 @@ GetOpt::operator()()
   if
     (   nlongopts
     &&  (
+#if defined LMI_CLANG
+#   pragma clang diagnostic push
+#   pragma clang diagnostic ignored "-Wcomma"
+#endif // defined LMI_CLANG
+            // clang: "possible misuse of comma operator"
             ('-' == nargv[optind][1]) ? (nextchar++, 1) : (0)
+#if defined LMI_CLANG
+#   pragma clang diagnostic pop
+#endif // defined LMI_CLANG
         ||  (
                 nlong_only
             &&  (
diff --git a/ledger.cpp b/ledger.cpp
index 300194d0..3b85686e 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -239,7 +239,8 @@ Ledger& Ledger::PlusEq(Ledger const& a_Addend)
             ((*this_i).second.LapseYear
             ,(*addend_i).second.LapseYear
             );
-        ++this_i, ++addend_i;
+        ++this_i;
+        ++addend_i;
         }
 
     LMI_ASSERT(this_i == l_map_rep.end() && addend_i == lm_addend.end());
diff --git a/zero.hpp b/zero.hpp
index 695a1f94..9e9d01f2 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -1373,9 +1373,17 @@ int rroot_(FunctionalType& f, int* nprob, int* neps, 
double* eps,
         fu = fb;
     }
     c0 = u - fu / (fb - fa) * 2. * (*b - *a);
+#if defined LMI_CLANG
+#   pragma clang diagnostic push
+#   pragma clang diagnostic ignored "-Wcomma"
+#endif // defined LMI_CLANG
+    // clang: "possible misuse of comma operator"
     if ((d_1 = c0 - u, std::fabs(d_1)) > (*b - *a) * .5) {
         c0 = *a + (*b - *a) * .5;
     }
+#if defined LMI_CLANG
+#   pragma clang diagnostic pop
+#endif // defined LMI_CLANG
 
 /* CALL SUBROUTINE "BRACKT" TO GET A SHRINKED ENCLOSING INTERVAL AS */
 /* WELL AS TO UPDATE THE TERMINATION CRITERION. STOP THE PROCEDURE */



reply via email to

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