lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master be063aa 4/6: Merge "stifle" function template


From: Greg Chicares
Subject: [lmi-commits] [lmi] master be063aa 4/6: Merge "stifle" function templates
Date: Wed, 27 Oct 2021 18:22:21 -0400 (EDT)

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

    Merge "stifle" function templates
    
    See:
      https://lists.nongnu.org/archive/html/lmi/2021-10/msg00036.html
---
 bourn_cast_test.cpp       |  6 +++---
 cache_file_reads_test.cpp |  6 +++---
 currency_test.cpp         | 10 +++++-----
 dbnames.cpp               |  4 ++--
 fenv_lmi.cpp              |  6 +++---
 financial_test.cpp        |  6 +++---
 input_sequence_parser.cpp |  6 +++---
 input_test.cpp            |  6 +++---
 math_functions_test.cpp   | 14 +++++++-------
 miscellany.hpp            | 22 ++--------------------
 monnaie_test.cpp          |  6 +++---
 numeric_io_test.cpp       |  8 ++++----
 test_main.cpp             |  4 ++--
 timer_test.cpp            |  4 ++--
 xml_serialize_test.cpp    |  6 +++---
 zero_test.cpp             |  4 ++--
 16 files changed, 50 insertions(+), 68 deletions(-)

diff --git a/bourn_cast_test.cpp b/bourn_cast_test.cpp
index cdd89fa..971140a 100644
--- a/bourn_cast_test.cpp
+++ b/bourn_cast_test.cpp
@@ -49,7 +49,7 @@ inline To bourn_cast(From from)
 #   include "bourn_cast.hpp"
 #endif // !defined TEST_BOOST_CAST_INSTEAD
 
-#include "miscellany.hpp"               // stifle_warning_for_unused_variable()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "stl_extensions.hpp"           // nonstd::power()
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -670,7 +670,7 @@ void mete_static()
         {
         z = static_cast<To>(j);
         }
-    stifle_warning_for_unused_variable(z);
+    stifle_unused_warning(z);
 }
 
 /// Speed test: convert one million times, using bourn_cast.
@@ -687,7 +687,7 @@ void mete_bourn()
         {
         z = bourn_cast<To>(j);
         }
-    stifle_warning_for_unused_variable(z);
+    stifle_unused_warning(z);
 }
 
 void assay_speed()
diff --git a/cache_file_reads_test.cpp b/cache_file_reads_test.cpp
index c9e519a..55730cf 100644
--- a/cache_file_reads_test.cpp
+++ b/cache_file_reads_test.cpp
@@ -24,7 +24,7 @@
 #include "cache_file_reads.hpp"
 
 #include "istream_to_string.hpp"
-#include "miscellany.hpp"               // ios_in_binary()
+#include "miscellany.hpp"               // ios_in_binary(), 
stifle_unused_warning()
 #include "path.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -100,14 +100,14 @@ void cache_file_reads_test::mete_uncached()
 {
     X const x("sample.ill");
     std::string::size_type volatile z = x.s().size();
-    stifle_warning_for_unused_value(z);
+    stifle_unused_warning(z);
 }
 
 void cache_file_reads_test::mete_cached()
 {
     X const& x(*X::read_via_cache("sample.ill"));
     std::string::size_type volatile z = x.s().size();
-    stifle_warning_for_unused_value(z);
+    stifle_unused_warning(z);
 }
 
 int test_main(int, char*[])
diff --git a/currency_test.cpp b/currency_test.cpp
index ac439ac..9558980 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -23,7 +23,7 @@
 
 #include "currency.hpp"
 
-#include "miscellany.hpp"               // stifle_warning_for_unused_variable()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "round_to.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -166,10 +166,10 @@ void currency_test::test_literals()
     // These are evaluated at compile time, even though this is not
     // a constexpr context:
     auto compile_time_constant_pos( 9007199254740992_cents);
-    stifle_warning_for_unused_variable(compile_time_constant_pos);
+    stifle_unused_warning(compile_time_constant_pos);
 
     auto compile_time_constant_neg(-9007199254740992_cents);
-    stifle_warning_for_unused_variable(compile_time_constant_neg);
+    stifle_unused_warning(compile_time_constant_neg);
 
     // These would be compile-time errors:
 //  auto error_at_compile_time_pos( 9007199254740993_cents);
@@ -297,7 +297,7 @@ void currency_test::mete_humongous()
     for(int i = 0; i < 100000; ++i)
         {
         currency volatile z = std::min(extreme, value);
-        stifle_warning_for_unused_variable(z);
+        stifle_unused_warning(z);
         }
 }
 
@@ -309,7 +309,7 @@ void currency_test::mete_infinite()
     for(int i = 0; i < 100000; ++i)
         {
         currency volatile z = std::min(extreme, value);
-        stifle_warning_for_unused_variable(z);
+        stifle_unused_warning(z);
         }
 }
 
diff --git a/dbnames.cpp b/dbnames.cpp
index 3b5807a..4db7683 100644
--- a/dbnames.cpp
+++ b/dbnames.cpp
@@ -27,7 +27,7 @@
 #include "alert.hpp"
 #include "assert_lmi.hpp"
 #include "map_lookup.hpp"
-#include "miscellany.hpp"
+#include "miscellany.hpp"               // stifle_unused_warning()
 
 #include <map>
 
@@ -80,7 +80,7 @@ std::vector<db_names> const& static_get_db_names()
     static std::vector<db_names> const v(static_DBNames, static_DBNames + n);
 
     static bool volatile b = check_order(v);
-    stifle_warning_for_unused_variable(b);
+    stifle_unused_warning(b);
 
     return v;
 }
diff --git a/fenv_lmi.cpp b/fenv_lmi.cpp
index cd7f50a..61a4cfb 100644
--- a/fenv_lmi.cpp
+++ b/fenv_lmi.cpp
@@ -25,7 +25,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
-#include "miscellany.hpp"               // stifle_warning_for_unused_variable()
+#include "miscellany.hpp"               // stifle_unused_warning()
 
 #include <cfenv>
 #include <iomanip>
@@ -105,7 +105,7 @@ void fenv_precision(e_ieee754_precision precision_mode)
     control_word.pc(pc);
     x87_control_word(control_word.cw());
 #else  // !defined LMI_X87
-    stifle_warning_for_unused_variable(precision_mode);
+    stifle_unused_warning(precision_mode);
     throw std::logic_error("Unable to set hardware precision.");
 #endif // !defined LMI_X87
 }
@@ -239,7 +239,7 @@ bool fenv_validate(enum_fenv_indulgence indulgence)
         fenv_initialize();
         }
 #else  // !defined LMI_X87
-    stifle_warning_for_unused_variable(indulgence);
+    stifle_unused_warning(indulgence);
 #endif // !defined LMI_X87
 
     bool okay = fenv_is_valid();
diff --git a/financial_test.cpp b/financial_test.cpp
index b7cd882..966ec3d 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -24,7 +24,7 @@
 #include "financial.hpp"
 
 #include "materially_equal.hpp"
-#include "miscellany.hpp"               // stifle_warning_for_unused_value()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "ssize_lmi.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -82,7 +82,7 @@ void mete_0
             );
         unoptimizable = results.front();
         }
-    stifle_warning_for_unused_value(unoptimizable);
+    stifle_unused_warning(unoptimizable);
 }
 
 void mete_1
@@ -105,7 +105,7 @@ void mete_1
             );
         unoptimizable = results.front();
         }
-    stifle_warning_for_unused_value(unoptimizable);
+    stifle_unused_warning(unoptimizable);
 }
 
 int test_main(int, char*[])
diff --git a/input_sequence_parser.cpp b/input_sequence_parser.cpp
index 60cca94..d7dfe98 100644
--- a/input_sequence_parser.cpp
+++ b/input_sequence_parser.cpp
@@ -25,7 +25,7 @@
 
 #include "assert_lmi.hpp"
 #include "contains.hpp"
-#include "miscellany.hpp"               // is_ok_for_cctype(), rtrim()
+#include "miscellany.hpp"               // is_ok_for_cctype(), rtrim(), 
stifle_unused_warning()
 
 #include <algorithm>                    // copy()
 #include <cctype>                       // isalnum(), isspace()
@@ -51,8 +51,8 @@ SequenceParser::SequenceParser
     ,keywords_only_                 {a_keywords_only}
 {
     // Suppress clang '-Wunused-private-field' warnings:
-    stifle_warning_for_unused_value(inforce_duration_);
-    stifle_warning_for_unused_value(effective_year_);
+    stifle_unused_warning(inforce_duration_);
+    stifle_unused_warning(effective_year_);
     sequence();
     diagnostic_messages_ = diagnostics_.str();
 }
diff --git a/input_test.cpp b/input_test.cpp
index 2393afe..6314c91 100644
--- a/input_test.cpp
+++ b/input_test.cpp
@@ -35,7 +35,7 @@
 #include "dbdict.hpp"
 #include "dbnames.hpp"
 #include "global_settings.hpp"
-#include "miscellany.hpp"
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "oecumenic_enumerations.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -520,14 +520,14 @@ void input_test::mete_equal_op()
     static Input const x;
     static Input const y(x);
     bool volatile b(x == y);
-    stifle_warning_for_unused_value(b);
+    stifle_unused_warning(b);
 }
 
 void input_test::mete_overhead()
 {
     xml_lmi::xml_document document("root");
     xml::element& root = document.root_node();
-    stifle_warning_for_unused_value(root);
+    stifle_unused_warning(root);
 }
 
 void input_test::mete_read(xml::element& xml_data)
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 6a324b2..e6c02b9 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -25,7 +25,7 @@
 
 #include "fenv_lmi.hpp"
 #include "materially_equal.hpp"
-#include "miscellany.hpp"               // stifle_warning_for_unused_value()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "stl_extensions.hpp"           // nonstd::power()
 #include "test_tools.hpp"
 #include "timer.hpp"
@@ -207,7 +207,7 @@ void mete0()
         x = d_upper_12_from_i_naive        <double>()(0.04);
         x = net_i_from_gross_naive<double,365>()(0.04, 0.007, 0.003);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 // This implementation uses production functors.
@@ -221,7 +221,7 @@ void mete1()
         x = d_upper_12_from_i        <double>()(0.04);
         x = net_i_from_gross<double,365>()(0.04, 0.007, 0.003);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 void mete2()
@@ -231,7 +231,7 @@ void mete2()
         {
         x = i_upper_n_over_n_from_i_T<double,365>()(0.01);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 void mete3()
@@ -241,7 +241,7 @@ void mete3()
         {
         x = i_upper_n_over_n_from_i_T<long double,365>()(0.01);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 // These 'mete[45]' functions calculate 10^-9 in different ways.
@@ -260,7 +260,7 @@ void mete4()
         {
         x = 1.0 / nonstd::power(base, exponent);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 void mete5()
@@ -272,7 +272,7 @@ void mete5()
         {
         x = std::pow(base, exponent);
         }
-    stifle_warning_for_unused_value(x);
+    stifle_unused_warning(x);
 }
 
 void assay_speed()
diff --git a/miscellany.hpp b/miscellany.hpp
index 5fd12ea..362ac3a 100644
--- a/miscellany.hpp
+++ b/miscellany.hpp
@@ -290,28 +290,10 @@ inline unsigned char lmi_toupper(unsigned char c)
     return static_cast<unsigned char>(std::toupper(c));
 }
 
-/// DWISOTT
-///
-/// Perhaps this function template's only legitimate use is within a
-/// conditional-inclusion [16.1] block.
+/// Avoid compiler warning for unused variable or unused value.
 
 template<typename T>
-inline void stifle_warning_for_unused_variable(T const&)
+inline void stifle_unused_warning(T const&)
 {}
 
-/// DWISOTT
-///
-/// Casting to void is always permitted by 5.2.9/4 via 5.4/5 (cf. C99
-/// 6.3.2.2).
-///
-/// Taking the argument's address prevents this gcc warning:
-///   "object of type [X] will not be accessed in void context"
-/// for volatile types.
-
-template<typename T>
-inline void stifle_warning_for_unused_value(T const& t)
-{
-    (void)&t;
-}
-
 #endif // miscellany_hpp
diff --git a/monnaie_test.cpp b/monnaie_test.cpp
index 60de3e1..8fe3e67 100644
--- a/monnaie_test.cpp
+++ b/monnaie_test.cpp
@@ -25,7 +25,7 @@
 
 #include "bourn_cast.hpp"
 #include "materially_equal.hpp"
-#include "miscellany.hpp"               // stifle_warning_for_unused_value()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 #include "timer.hpp"
 
@@ -267,11 +267,11 @@ void do_some_arithmetic(T t)
         u += t - f;
         u = convert_from_double<T>(std::floor(convert_to_double(u) * 1.03));
         T volatile v(u);
-        stifle_warning_for_unused_value(v);
+        stifle_unused_warning(v);
         }
 
     T volatile w(t);
-    stifle_warning_for_unused_value(w);
+    stifle_unused_warning(w);
 }
 
 void mete_double()
diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index d020db4..3025a7b 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -25,7 +25,7 @@
 
 #include "handle_exceptions.hpp"        // report_exception()
 #include "ieee754.hpp"                  // infinity<>()
-#include "miscellany.hpp"
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 #include "timer.hpp"
 
@@ -96,7 +96,7 @@ void mete_two_thirds()
 {
     std::string s = numeric_io_cast<std::string>(2.0 / 3.0);
     double d = numeric_io_cast<double>(s);
-    stifle_warning_for_unused_value(d);
+    stifle_unused_warning(d);
 }
 
 #if defined TEST_BOOST_IMPLEMENTATION_TOO
@@ -104,7 +104,7 @@ void mete_two_thirds_boost()
 {
     std::string s = boost::lexical_cast<std::string>(2.0 / 3.0);
     double d = boost::lexical_cast<double>(s);
-    stifle_warning_for_unused_value(d);
+    stifle_unused_warning(d);
 }
 #endif // defined TEST_BOOST_IMPLEMENTATION_TOO
 
@@ -112,7 +112,7 @@ void mete_infinity()
 {
     std::string s = numeric_io_cast<std::string>(infinity<double>());
     double d = numeric_io_cast<double>(s);
-    stifle_warning_for_unused_value(d);
+    stifle_unused_warning(d);
 }
 
 // These tests generally assume IEC 60559 floating point. Hardware
diff --git a/test_main.cpp b/test_main.cpp
index 922a4e0..b3f6bc8 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -61,7 +61,7 @@
 #include "exit_codes.hpp"
 #include "fenv_lmi.hpp"
 #include "force_linking.hpp"
-#include "miscellany.hpp"               // stifle_warning_for_unused_value()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 
 #include <atomic>
@@ -164,7 +164,7 @@ int cpp_main(int argc, char* argv[])
     fenv_initialize();
 
     int result = 0;
-    stifle_warning_for_unused_value(result);
+    stifle_unused_warning(result);
 
     try
         {
diff --git a/timer_test.cpp b/timer_test.cpp
index e940d37..e30d313 100644
--- a/timer_test.cpp
+++ b/timer_test.cpp
@@ -24,7 +24,7 @@
 #include "timer.hpp"
 
 #include "contains.hpp"
-#include "miscellany.hpp"
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 
 #include <cmath>                        // log10()
@@ -39,7 +39,7 @@ void foo()
     for(int j = 0; j < 100; ++j)
         {
         d = std::log10(1 + j * j);
-        stifle_warning_for_unused_value(d);
+        stifle_unused_warning(d);
         }
 }
 
diff --git a/xml_serialize_test.cpp b/xml_serialize_test.cpp
index 3020870..eeb7275 100644
--- a/xml_serialize_test.cpp
+++ b/xml_serialize_test.cpp
@@ -23,7 +23,7 @@
 
 #include "xml_serialize.hpp"
 
-#include "miscellany.hpp"               // stifle_warning_for_unused_variable()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 #include "timer.hpp"
 
@@ -118,7 +118,7 @@ void mete_write_0()
 {
     xml_lmi::xml_document document("eraseme");
     xml::element& root = document.root_node();
-    stifle_warning_for_unused_variable(root);
+    stifle_unused_warning(root);
     dom_string = document.str();
 }
 
@@ -126,7 +126,7 @@ void mete_read_0()
 {
     xml_lmi::dom_parser parser(dom_string.c_str(), dom_string.size());
     xml::element const& root = parser.root_node("eraseme");
-    stifle_warning_for_unused_variable(root);
+    stifle_unused_warning(root);
 }
 
 // These /mete_._[write|read]/ functions are like write() and read()
diff --git a/zero_test.cpp b/zero_test.cpp
index 1e0b742..5a787d0 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -26,7 +26,7 @@
 #include "assert_lmi.hpp"
 #include "materially_equal.hpp"
 #include "math_functions.hpp"           // signum()
-#include "miscellany.hpp"               // stifle_warning_for_unused_variable()
+#include "miscellany.hpp"               // stifle_unused_warning()
 #include "test_tools.hpp"
 
 #include <algorithm>                    // max()
@@ -249,7 +249,7 @@ void test_a_decimal_function
         INVOKE_LMI_TEST_EQUAL(n_eval, r.n_eval, file, line);
         }
 #endif // defined LMI_X86_64 && defined LMI_POSIX
-    stifle_warning_for_unused_variable(n_eval);
+    stifle_unused_warning(n_eval);
 }
 
 /// Test with all biases, asserting obvious invariants.



reply via email to

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