Skip to content

Commit c479e0c

Browse files
committed
[libc++] NFC: Fix several GCC warnings in the test suite
- Several -Wshadow warnings - Several places where we did not initialize our base class explicitly - Unused variable warnings - Some tautological comparisons - Some places where we'd pass null arguments to functions expecting non-null (in unevaluated contexts) - Add a few pragmas to turn off spurious warnings - Fix warnings about declarations that don't declare anything - Properly disable deprecation warnings in ext/ tests (the pragmas we were using didn't work on GCC) - Disable include_as_c.sh.cpp because GCC complains about C++ flags when compiling as C. I couldn't find a way to fix this one properly, so I'm disabling the test. This isn't great, but at least we'll be able to enable warnings in the whole test suite with GCC.
1 parent 1d7786d commit c479e0c

File tree

95 files changed

+282
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+282
-278
lines changed

libcxx/src/filesystem/filesystem_common.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include "filesystem"
1414
#include "array"
1515
#include "chrono"
16-
#include "cstdlib"
1716
#include "climits"
17+
#include "cstdlib"
18+
#include "ctime"
1819

1920
#include <unistd.h>
2021
#include <sys/stat.h>
@@ -47,7 +48,7 @@ static string format_string_imp(const char* msg, ...) {
4748
struct GuardVAList {
4849
va_list& target;
4950
bool active = true;
50-
GuardVAList(va_list& target) : target(target), active(true) {}
51+
GuardVAList(va_list& tgt) : target(tgt), active(true) {}
5152
void clear() {
5253
if (active)
5354
va_end(target);
@@ -134,50 +135,50 @@ path error_value<path>() {
134135

135136
template <class T>
136137
struct ErrorHandler {
137-
const char* func_name;
138-
error_code* ec = nullptr;
139-
const path* p1 = nullptr;
140-
const path* p2 = nullptr;
138+
const char* func_name_;
139+
error_code* ec_ = nullptr;
140+
const path* p1_ = nullptr;
141+
const path* p2_ = nullptr;
141142

142143
ErrorHandler(const char* fname, error_code* ec, const path* p1 = nullptr,
143144
const path* p2 = nullptr)
144-
: func_name(fname), ec(ec), p1(p1), p2(p2) {
145-
if (ec)
146-
ec->clear();
145+
: func_name_(fname), ec_(ec), p1_(p1), p2_(p2) {
146+
if (ec_)
147+
ec_->clear();
147148
}
148149

149-
T report(const error_code& m_ec) const {
150-
if (ec) {
151-
*ec = m_ec;
150+
T report(const error_code& ec) const {
151+
if (ec_) {
152+
*ec_ = ec;
152153
return error_value<T>();
153154
}
154-
string what = string("in ") + func_name;
155-
switch (bool(p1) + bool(p2)) {
155+
string what = string("in ") + func_name_;
156+
switch (bool(p1_) + bool(p2_)) {
156157
case 0:
157-
__throw_filesystem_error(what, m_ec);
158+
__throw_filesystem_error(what, ec);
158159
case 1:
159-
__throw_filesystem_error(what, *p1, m_ec);
160+
__throw_filesystem_error(what, *p1_, ec);
160161
case 2:
161-
__throw_filesystem_error(what, *p1, *p2, m_ec);
162+
__throw_filesystem_error(what, *p1_, *p2_, ec);
162163
}
163164
_LIBCPP_UNREACHABLE();
164165
}
165166

166167
template <class... Args>
167-
T report(const error_code& m_ec, const char* msg, Args const&... args) const {
168-
if (ec) {
169-
*ec = m_ec;
168+
T report(const error_code& ec, const char* msg, Args const&... args) const {
169+
if (ec_) {
170+
*ec_ = ec;
170171
return error_value<T>();
171172
}
172173
string what =
173-
string("in ") + func_name + ": " + format_string(msg, args...);
174-
switch (bool(p1) + bool(p2)) {
174+
string("in ") + func_name_ + ": " + format_string(msg, args...);
175+
switch (bool(p1_) + bool(p2_)) {
175176
case 0:
176-
__throw_filesystem_error(what, m_ec);
177+
__throw_filesystem_error(what, ec);
177178
case 1:
178-
__throw_filesystem_error(what, *p1, m_ec);
179+
__throw_filesystem_error(what, *p1_, ec);
179180
case 2:
180-
__throw_filesystem_error(what, *p1, *p2, m_ec);
181+
__throw_filesystem_error(what, *p1_, *p2_, ec);
181182
}
182183
_LIBCPP_UNREACHABLE();
183184
}
@@ -197,8 +198,8 @@ struct ErrorHandler {
197198
using chrono::duration;
198199
using chrono::duration_cast;
199200

200-
using TimeSpec = struct ::timespec;
201-
using StatT = struct ::stat;
201+
using TimeSpec = std::timespec;
202+
using StatT = struct stat;
202203

203204
template <class FileTimeT, class TimeT,
204205
bool IsFloat = is_floating_point<typename FileTimeT::rep>::value>

libcxx/test/libcxx/containers/gnu_cxx/hash_map.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Prevent emission of the deprecated warning.
10-
#ifdef __clang__
11-
#pragma clang diagnostic ignored "-W#warnings"
12-
#endif
13-
#ifdef __GNUC__
14-
#pragma GCC diagnostic ignored "-Wcpp"
9+
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
10+
#if defined(__DEPRECATED)
11+
# undef __DEPRECATED
1512
#endif
1613

1714
#include <ext/hash_map>

libcxx/test/libcxx/containers/gnu_cxx/hash_map_name_lookup.pass.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Prevent emission of the deprecated warning.
10-
#ifdef __clang__
11-
#pragma clang diagnostic ignored "-W#warnings"
12-
#endif
13-
#ifdef __GNUC__
14-
#pragma GCC diagnostic push "-Wcpp"
15-
#endif
16-
179
// Poison the std:: names we might use inside __gnu_cxx to ensure they're
1810
// properly qualified.
1911
struct allocator;
2012
struct pair;
2113
struct equal_to;
2214
struct unique_ptr;
15+
16+
// Prevent <ext/hash_map> from generating deprecated warnings for this test.
17+
#if defined(__DEPRECATED)
18+
# undef __DEPRECATED
19+
#endif
20+
2321
#include <ext/hash_map>
2422

2523
#include "test_macros.h"

libcxx/test/libcxx/containers/gnu_cxx/hash_set.pass.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Prevent emission of the deprecated warning.
10-
#ifdef __clang__
11-
#pragma clang diagnostic ignored "-W#warnings"
12-
#endif
13-
#ifdef __GNUC__
14-
#pragma GCC diagnostic ignored "-Wcpp"
9+
// Prevent <ext/hash_set> from generating deprecated warnings for this test.
10+
#if defined(__DEPRECATED)
11+
# undef __DEPRECATED
1512
#endif
1613

1714
#include <ext/hash_set>

libcxx/test/libcxx/containers/gnu_cxx/hash_set_name_lookup.pass.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// Prevent emission of the deprecated warning.
10-
#ifdef __clang__
11-
#pragma clang diagnostic ignored "-W#warnings"
12-
#endif
13-
#ifdef __GNUC__
14-
#pragma GCC diagnostic ignored "-Wcpp"
15-
#endif
16-
179
// Poison the std:: names we might use inside __gnu_cxx to ensure they're
1810
// properly qualified.
1911
struct allocator;
2012
struct pair;
2113
struct equal_to;
2214
struct unique_ptr;
15+
16+
// Prevent <ext/hash_set> from generating deprecated warnings for this test.
17+
#if defined(__DEPRECATED)
18+
# undef __DEPRECATED
19+
#endif
20+
2321
#include <ext/hash_set>
2422

2523
#include "test_macros.h"

libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ static_assert(BlockSize<LargeT>::value == 16, "");
5353

5454
const auto& AllocBytes = malloc_allocator_base::outstanding_bytes;
5555

56-
template <class DT>
56+
template <class Deque>
5757
struct PrintOnFailure {
58-
explicit PrintOnFailure(DT const& d) : d(&d) {}
58+
explicit PrintOnFailure(Deque const& deque) : deque_(&deque) {}
5959

6060
~PrintOnFailure() {
6161
if (::rapid_cxx_test::get_reporter().current_failure().type
6262
!= ::rapid_cxx_test::failure_type::none) {
63-
print(*d);
63+
print(*deque_);
6464
}
6565
}
6666
private:
67-
const DT* d;
67+
const Deque* deque_;
6868

6969
PrintOnFailure(PrintOnFailure const&) = delete;
7070
};

libcxx/test/libcxx/include_as_c.sh.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
// We're building as C, so this test doesn't work when building with modules.
1111
// UNSUPPORTED: -fmodules
1212

13+
// GCC complains about unrecognized arguments because we're compiling the
14+
// file as C, but we're passing C++ flags on the command-line.
15+
// UNSUPPORTED: gcc
16+
1317
// Test that the C wrapper headers can be included when compiling them as C.
1418

1519
// NOTE: It's not common or recommended to have libc++ in the header search

libcxx/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ struct MySearcher {
5858

5959
namespace User {
6060
struct S {
61-
S(int x) : x(x) {}
62-
int x;
61+
S(int x) : x_(x) {}
62+
int x_;
6363
};
6464
bool operator==(S lhs, S rhs)
6565
{
66-
return lhs.x == rhs.x;
66+
return lhs.x_ == rhs.x_;
6767
}
6868
template <class T, class U>
6969
void make_pair(T&&, U&&) = delete;

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ struct test
2828
explicit test(const test_allocator<int>& a) : base(a) {}
2929
test(const value_compare& comp, const test_allocator<int>& a)
3030
: base(comp, c, a) {}
31-
test(const value_compare& comp, const container_type& c,
32-
const test_allocator<int>& a) : base(comp, c, a) {}
31+
test(const value_compare& comp, const container_type& container,
32+
const test_allocator<int>& a) : base(comp, container, a) {}
3333
#if TEST_STD_VER >= 11
34-
test(const value_compare& comp, container_type&& c,
35-
const test_allocator<int>& a) : base(comp, std::move(c), a) {}
34+
test(const value_compare& comp, container_type&& container,
35+
const test_allocator<int>& a) : base(comp, std::move(container), a) {}
3636
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
3737
#endif
3838
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ struct test
2626
typedef typename base::value_compare value_compare;
2727

2828
explicit test(const test_allocator<int>& a) : base(a) {}
29-
test(const value_compare& comp, const test_allocator<int>& a)
30-
: base(comp, a) {}
31-
test(const value_compare& comp, const container_type& c,
32-
const test_allocator<int>& a) : base(comp, c, a) {}
29+
test(const value_compare& compare, const test_allocator<int>& a)
30+
: base(compare, a) {}
31+
test(const value_compare& compare, const container_type& container,
32+
const test_allocator<int>& a) : base(compare, container, a) {}
3333
#if TEST_STD_VER >= 11
34-
test(const value_compare& comp, container_type&& c,
35-
const test_allocator<int>& a) : base(comp, std::move(c), a) {}
34+
test(const value_compare& compare, container_type&& container,
35+
const test_allocator<int>& a) : base(compare, std::move(container), a) {}
3636
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
3737
#endif
3838
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ struct test
3737
typedef typename base::value_compare value_compare;
3838

3939
explicit test(const test_allocator<int>& a) : base(a) {}
40-
test(const value_compare& comp, const test_allocator<int>& a)
41-
: base(comp, a) {}
42-
test(const value_compare& comp, const container_type& c,
43-
const test_allocator<int>& a) : base(comp, c, a) {}
40+
test(const value_compare& compare, const test_allocator<int>& a)
41+
: base(compare, a) {}
42+
test(const value_compare& compare, const container_type& container,
43+
const test_allocator<int>& a) : base(compare, container, a) {}
4444
#if TEST_STD_VER >= 11 // testing rvalue constructor
45-
test(const value_compare& comp, container_type&& c,
46-
const test_allocator<int>& a) : base(comp, std::move(c), a) {}
45+
test(const value_compare& compare, container_type&& container,
46+
const test_allocator<int>& a) : base(compare, std::move(container), a) {}
4747
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
4848
#endif
4949
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ struct test
3737
typedef typename base::value_compare value_compare;
3838

3939
explicit test(const test_allocator<int>& a) : base(a) {}
40-
test(const value_compare& comp, const test_allocator<int>& a)
41-
: base(comp, a) {}
42-
test(const value_compare& comp, const container_type& c,
43-
const test_allocator<int>& a) : base(comp, c, a) {}
40+
test(const value_compare& compare, const test_allocator<int>& a)
41+
: base(compare, a) {}
42+
test(const value_compare& compare, const container_type& container,
43+
const test_allocator<int>& a) : base(compare, container, a) {}
4444
#if TEST_STD_VER >= 11 // testing rvalue ctor
45-
test(const value_compare& comp, container_type&& c,
46-
const test_allocator<int>& a) : base(comp, std::move(c), a) {}
45+
test(const value_compare& compare, container_type&& container,
46+
const test_allocator<int>& a) : base(compare, std::move(container), a) {}
4747
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
4848
#endif
4949
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct test
3636
typedef typename base::value_compare value_compare;
3737

3838
explicit test(const test_allocator<int>& a) : base(a) {}
39-
test(const value_compare& comp, const test_allocator<int>& a)
40-
: base(comp, c, a) {}
41-
test(const value_compare& comp, const container_type& c,
42-
const test_allocator<int>& a) : base(comp, c, a) {}
39+
test(const value_compare& compare, const test_allocator<int>& a)
40+
: base(compare, c, a) {}
41+
test(const value_compare& compare, const container_type& container,
42+
const test_allocator<int>& a) : base(compare, container, a) {}
4343
test(const test& q, const test_allocator<int>& a) : base(q, a) {}
4444
test_allocator<int> get_allocator() {return c.get_allocator();}
4545

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ struct test
4141
typedef typename base::value_compare value_compare;
4242

4343
explicit test(const test_allocator<int>& a) : base(a) {}
44-
test(const value_compare& comp, const test_allocator<int>& a)
45-
: base(comp, c, a) {}
46-
test(const value_compare& comp, const container_type& c,
47-
const test_allocator<int>& a) : base(comp, c, a) {}
48-
test(const value_compare& comp, container_type&& c,
49-
const test_allocator<int>& a) : base(comp, std::move(c), a) {}
44+
test(const value_compare& compare, const test_allocator<int>& a)
45+
: base(compare, c, a) {}
46+
test(const value_compare& compare, const container_type& container,
47+
const test_allocator<int>& a) : base(compare, container, a) {}
48+
test(const value_compare& compare, container_type&& container,
49+
const test_allocator<int>& a) : base(compare, std::move(container), a) {}
5050
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
5151
test_allocator<int> get_allocator() {return c.get_allocator();}
5252

libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/deduct.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ int main(int, char**)
108108
// has to match the type of the one used by the underlying container
109109
typedef long double T;
110110
typedef std::greater<T> Comp;
111-
typedef test_allocator<T> A;
112-
typedef std::deque<T, A> Cont;
111+
typedef test_allocator<T> Alloc;
112+
typedef std::deque<T, Alloc> Cont;
113113

114114
Cont c{2,3,0,1};
115115
std::priority_queue<T, Cont, Comp> source(Comp(), c);
116-
std::priority_queue pri(source, A(2)); // queue(queue &, allocator)
116+
std::priority_queue pri(source, Alloc(2)); // queue(queue &, allocator)
117117
static_assert(std::is_same_v<decltype(pri)::value_type, T>, "");
118118
static_assert(std::is_same_v<decltype(pri)::container_type, Cont>, "");
119119
assert(pri.size() == 4);

libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ struct test
2323
typedef std::queue<int, std::deque<int, test_allocator<int> > > base;
2424

2525
explicit test(const test_allocator<int>& a) : base(a) {}
26-
test(const container_type& c, const test_allocator<int>& a) : base(c, a) {}
26+
test(const container_type& container, const test_allocator<int>& a) : base(container, a) {}
2727
#if TEST_STD_VER >= 11
28-
test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {}
28+
test(container_type&& container, const test_allocator<int>& a) : base(std::move(container), a) {}
2929
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
3030
#endif
3131
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ struct test
3636
typedef std::queue<int, C> base;
3737

3838
explicit test(const test_allocator<int>& a) : base(a) {}
39-
test(const container_type& c, const test_allocator<int>& a) : base(c, a) {}
39+
test(const container_type& container, const test_allocator<int>& a) : base(container, a) {}
4040
#if TEST_STD_VER >= 11
41-
test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {}
41+
test(container_type&& container, const test_allocator<int>& a) : base(std::move(container), a) {}
4242
test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
4343
#endif
4444
test_allocator<int> get_allocator() {return c.get_allocator();}

libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct test
3838
typedef typename base::container_type container_type;
3939

4040
explicit test(const allocator_type& a) : base(a) {}
41-
test(const container_type& c, const allocator_type& a) : base(c, a) {}
41+
test(const container_type& container, const allocator_type& a) : base(container, a) {}
4242
test(const test& q, const allocator_type& a) : base(q, a) {}
4343
allocator_type get_allocator() {return this->c.get_allocator();}
4444
};

0 commit comments

Comments
 (0)