Bug 1732208 - Silence the unused-but-set-variable warning in xpcom. r=xpcom-reviewers,mccr8

xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp(130,22): error: variable 'x' set but not used [-Werror,-Wunused-but-set-variable]
    volatile uint8_t x = 0;
                     ^
xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp(152,12): error: variable 'consumed' set but not used [-Werror,-Wunused-but-set-variable]
    size_t consumed = 0;
           ^
xpcom/tests/gtest/TestSTLWrappers.cpp:48:7: error: variable 'rv' set but not used [-Werror,-Wunused-but-set-variable]
  int rv = 1;
      ^

Differential Revision: https://phabricator.services.mozilla.com/D126462
This commit is contained in:
Mike Hommey 2021-09-28 00:02:48 +00:00
parent b386a9ea29
commit dcfb8d38be
2 changed files with 2 additions and 6 deletions

View file

@ -134,6 +134,7 @@ class MemoryEater {
// and dereference it. // and dereference it.
x ^= *(base + i * kPageSize + rand() % kPageSize); x ^= *(base + i * kPageSize + rand() % kPageSize);
} }
(void)x;
} }
static uint32_t GetAvailablePhysicalMemoryInMb() { static uint32_t GetAvailablePhysicalMemoryInMb() {
@ -149,7 +150,6 @@ class MemoryEater {
constexpr size_t kMinGranularity = 64 * 1024; constexpr size_t kMinGranularity = 64 * 1024;
size_t currentSize = aSize; size_t currentSize = aSize;
size_t consumed = 0;
while (aSize >= kMinGranularity) { while (aSize >= kMinGranularity) {
if (!GetAvailablePhysicalMemoryInMb()) { if (!GetAvailablePhysicalMemoryInMb()) {
// If the available physical memory is less than 1MB, we finish // If the available physical memory is less than 1MB, we finish
@ -172,7 +172,6 @@ class MemoryEater {
} }
aSize -= currentSize; aSize -= currentSize;
consumed += currentSize;
// VirtualAlloc consumes the commit space, but we need to *touch* memory // VirtualAlloc consumes the commit space, but we need to *touch* memory
// to consume physical memory // to consume physical memory

View file

@ -45,14 +45,11 @@ void ShouldAbort() {
} }
std::vector<int> v; std::vector<int> v;
int rv = 1;
TRY { TRY {
// v.at(1) on empty v should abort; NOT throw an exception // v.at(1) on empty v should abort; NOT throw an exception
// (Do some arithmetic with result of v.at() to avoid (void)v.at(1);
// compiler warnings for unused variable/result.)
rv += v.at(1) ? 1 : 2;
} }
CATCH(const std::out_of_range&) { CATCH(const std::out_of_range&) {
fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n", stderr); fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n", stderr);