[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 32d5688 1/5: Improve a unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 32d5688 1/5: Improve a unit test |
Date: |
Tue, 9 Nov 2021 15:03:44 -0500 (EST) |
branch: master
commit 32d5688c26bb0744ad5488b35d3618d5d7016c16
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve a unit test
---
miscellany_test.cpp | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/miscellany_test.cpp b/miscellany_test.cpp
index 94f7c5f..3c3f565 100644
--- a/miscellany_test.cpp
+++ b/miscellany_test.cpp
@@ -491,19 +491,31 @@ void test_stifle_unused_warning()
#endif // defined some_undefined_condition
stifle_unused_warning(c);
- // Variable uninitialized at first...
+ // Leaving a variable uninitialized at declaration...
int volatile d;
-// stifle_unused_warning(d); // [see below]
- // ...though set later, but last value assigned...
+ // ...would not elicit an unused-value warning here--it has
+ // no unused value because it has no value at all yet:
+// stifle_unused_warning(d);
+ // ...so an unused-value warning must be stifled later...
for(int i = 0; i < 7; ++i)
{
d = static_cast<int>(std::clock());
}
- // ...is not subsequently used. In this case, for clang at least,
- // it is necessary to stifle the warning here:
- stifle_unused_warning(d);
- // rather than in the commented-out location above. See:
+ // ...e.g., here (for clang at least)--see:
// https://lists.nongnu.org/archive/html/lmi/2021-04/msg00058.html
+ // and
+ // https://lists.nongnu.org/archive/html/lmi/2021-10/msg00050.html
+ stifle_unused_warning(d);
+
+ // Same as immediately preceding case, except that the variable
+ // is initialized at declaration...
+ int volatile e {};
+ // ...so the warning can be stifled before the loop:
+ stifle_unused_warning(e);
+ for(int i = 0; i < 7; ++i)
+ {
+ e = static_cast<int>(std::clock());
+ }
partly_unused {0, 1};