Skip to content

Commit 8d31392

Browse files
committed
[libc++abi] Get rid of warnings when running the tests with GCC
1 parent 5a7bc5e commit 8d31392

16 files changed

+103
-52
lines changed

libcxxabi/src/cxa_guard_impl.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
#endif
5555
#endif
5656

57+
#if defined(__clang__)
58+
# pragma clang diagnostic push
59+
# pragma clang diagnostic ignored "-Wtautological-pointer-compare"
60+
#elif defined(__GNUC__)
61+
# pragma GCC diagnostic push
62+
# pragma GCC diagnostic ignored "-Waddress"
63+
#endif
64+
5765
// To make testing possible, this header is included from both cxa_guard.cpp
5866
// and a number of tests.
5967
//
@@ -112,25 +120,25 @@ class AtomicInt {
112120
public:
113121
using MemoryOrder = std::__libcpp_atomic_order;
114122

115-
explicit AtomicInt(IntType *b) : b(b) {}
123+
explicit AtomicInt(IntType *b) : b_(b) {}
116124
AtomicInt(AtomicInt const&) = delete;
117125
AtomicInt& operator=(AtomicInt const&) = delete;
118126

119127
IntType load(MemoryOrder ord) {
120-
return std::__libcpp_atomic_load(b, ord);
128+
return std::__libcpp_atomic_load(b_, ord);
121129
}
122130
void store(IntType val, MemoryOrder ord) {
123-
std::__libcpp_atomic_store(b, val, ord);
131+
std::__libcpp_atomic_store(b_, val, ord);
124132
}
125133
IntType exchange(IntType new_val, MemoryOrder ord) {
126-
return std::__libcpp_atomic_exchange(b, new_val, ord);
134+
return std::__libcpp_atomic_exchange(b_, new_val, ord);
127135
}
128136
bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) {
129-
return std::__libcpp_atomic_compare_exchange(b, expected, desired, ord_success, ord_failure);
137+
return std::__libcpp_atomic_compare_exchange(b_, expected, desired, ord_success, ord_failure);
130138
}
131139

132140
private:
133-
IntType *b;
141+
IntType *b_;
134142
};
135143

136144
//===----------------------------------------------------------------------===//
@@ -154,14 +162,7 @@ constexpr uint32_t (*PlatformThreadID)() = nullptr;
154162

155163

156164
constexpr bool PlatformSupportsThreadID() {
157-
#ifdef __clang__
158-
#pragma clang diagnostic push
159-
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
160-
#endif
161165
return +PlatformThreadID != nullptr;
162-
#ifdef __clang__
163-
#pragma clang diagnostic pop
164-
#endif
165166
}
166167

167168
//===----------------------------------------------------------------------===//
@@ -375,18 +376,18 @@ struct InitByteGlobalMutex
375376
LockGuard& operator=(LockGuard const&) = delete;
376377

377378
explicit LockGuard(const char* calling_func)
378-
: calling_func(calling_func) {
379+
: calling_func_(calling_func) {
379380
if (global_mutex.lock())
380-
ABORT_WITH_MESSAGE("%s failed to acquire mutex", calling_func);
381+
ABORT_WITH_MESSAGE("%s failed to acquire mutex", calling_func_);
381382
}
382383

383384
~LockGuard() {
384385
if (global_mutex.unlock())
385-
ABORT_WITH_MESSAGE("%s failed to release mutex", calling_func);
386+
ABORT_WITH_MESSAGE("%s failed to release mutex", calling_func_);
386387
}
387388

388389
private:
389-
const char* const calling_func;
390+
const char* const calling_func_;
390391
};
391392
};
392393

@@ -411,14 +412,7 @@ constexpr void (*PlatformFutexWake)(int*) = nullptr;
411412
#endif
412413

413414
constexpr bool PlatformSupportsFutex() {
414-
#ifdef __clang__
415-
#pragma clang diagnostic push
416-
#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
417-
#endif
418415
return +PlatformFutexWait != nullptr;
419-
#ifdef __clang__
420-
#pragma clang diagnostic pop
421-
#endif
422416
}
423417

424418
/// InitByteFutex - Manages initialization using atomics and the futex syscall
@@ -589,4 +583,10 @@ using SelectedImplementation =
589583
} // end namespace
590584
} // end namespace __cxxabiv1
591585

586+
#if defined(__clang__)
587+
# pragma clang diagnostic pop
588+
#elif defined(__GNUC__)
589+
# pragma GCC diagnostic pop
590+
#endif
591+
592592
#endif // LIBCXXABI_SRC_INCLUDE_CXA_GUARD_IMPL_H

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,9 +2313,9 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
23132313
TemplateParamList Params;
23142314

23152315
public:
2316-
ScopedTemplateParamList(AbstractManglingParser *Parser)
2317-
: Parser(Parser),
2318-
OldNumTemplateParamLists(Parser->TemplateParams.size()) {
2316+
ScopedTemplateParamList(AbstractManglingParser *TheParser)
2317+
: Parser(TheParser),
2318+
OldNumTemplateParamLists(TheParser->TemplateParams.size()) {
23192319
Parser->TemplateParams.push_back(&Params);
23202320
}
23212321
~ScopedTemplateParamList() {
@@ -5103,7 +5103,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() {
51035103
decltype(TemplateParams) OldParams;
51045104

51055105
public:
5106-
SaveTemplateParams(AbstractManglingParser *Parser) : Parser(Parser) {
5106+
SaveTemplateParams(AbstractManglingParser *TheParser) : Parser(TheParser) {
51075107
OldParams = std::move(Parser->TemplateParams);
51085108
Parser->TemplateParams.clear();
51095109
}

libcxxabi/test/catch_class_03.pass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
// UNSUPPORTED: no-exceptions
1616

17+
// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
18+
// by earlier handlers, which this test is exercising. We have to disable
19+
// warnings altogether to remove the error.
20+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
21+
// ADDITIONAL_COMPILE_FLAGS: -Wno-error
22+
1723
#include <exception>
1824
#include <stdlib.h>
1925
#include <assert.h>

libcxxabi/test/catch_class_04.pass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
// UNSUPPORTED: no-exceptions
1616

17+
// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
18+
// by earlier handlers, which this test is exercising. We have to disable
19+
// warnings altogether to remove the error.
20+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
21+
// ADDITIONAL_COMPILE_FLAGS: -Wno-error
22+
1723
#include <exception>
1824
#include <stdlib.h>
1925
#include <assert.h>

libcxxabi/test/catch_pointer_reference.pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
// (ignoring the top-level cv-qualifiers), or
1515
// * the handler is of type cv T or cv T& and T is an unambiguous base
1616
// class of E, or
17-
// / * the handler is of type cv1 T* cv2 and E is a pointer type that can \
18-
// | be converted to the type of the handler by either or both of |
19-
// | o a standard pointer conversion (4.10 [conv.ptr]) not involving |
20-
// | conversions to private or protected or ambiguous classes |
21-
// \ o a qualification conversion /
17+
// > * the handler is of type cv1 T* cv2 and E is a pointer type that can <
18+
// > be converted to the type of the handler by either or both of <
19+
// > o a standard pointer conversion (4.10 [conv.ptr]) not involving <
20+
// > conversions to private or protected or ambiguous classes <
21+
// > o a qualification conversion <
2222
// * the handler is a pointer or pointer to member type and E is
2323
// std::nullptr_t
2424
//

libcxxabi/test/catch_ptr.pass.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
// UNSUPPORTED: no-exceptions
1616

17+
// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
18+
// by earlier handlers, which this test is exercising. We have to disable
19+
// warnings altogether to remove the error.
20+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
21+
// ADDITIONAL_COMPILE_FLAGS: -Wno-error
22+
1723
#include <exception>
1824
#include <stdlib.h>
1925
#include <assert.h>
@@ -72,11 +78,11 @@ struct A
7278

7379
int A::count = 0;
7480

75-
A a(5);
81+
A global_a(5);
7682

7783
void f1()
7884
{
79-
throw &a;
85+
throw &global_a;
8086
assert(false);
8187
}
8288

libcxxabi/test/catch_ptr_02.pass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
// UNSUPPORTED: no-exceptions
1010

11+
// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
12+
// by earlier handlers, which this test is exercising. We have to disable
13+
// warnings altogether to remove the error.
14+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
15+
// ADDITIONAL_COMPILE_FLAGS: -Wno-error
16+
1117
#include <cassert>
1218

1319
// Clang emits warnings about exceptions of type 'Child' being caught by

libcxxabi/test/cxa_bad_cast.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main ()
4343
assert(false);
4444
((void)d);
4545
#ifndef TEST_HAS_NO_EXCEPTIONS
46-
} catch (std::bad_cast) {
46+
} catch (std::bad_cast const&) {
4747
// success
4848
return 0;
4949
} catch (...) {

libcxxabi/test/cxa_bad_typeid.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main ()
4141
test_bad_typeid(nullptr);
4242
assert(false);
4343
#ifndef TEST_HAS_NO_EXCEPTIONS
44-
} catch (std::bad_typeid) {
44+
} catch (std::bad_typeid const&) {
4545
// success
4646
return 0;
4747
} catch (...) {

libcxxabi/test/dynamic_cast.pass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
// This test explicitly tests dynamic cast with types that have inaccessible
1212
// bases.
1313
#if defined(__clang__)
14-
#pragma clang diagnostic ignored "-Winaccessible-base"
14+
# pragma clang diagnostic ignored "-Winaccessible-base"
15+
#elif defined(__GNUC__)
16+
# pragma GCC diagnostic ignored "-Winaccessible-base"
1517
#endif
1618

1719
typedef char Pad1[43981];

libcxxabi/test/dynamic_cast3.pass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// This test explicitly tests dynamic cast with types that have inaccessible
1313
// bases.
1414
#if defined(__clang__)
15-
#pragma clang diagnostic ignored "-Winaccessible-base"
15+
# pragma clang diagnostic ignored "-Winaccessible-base"
16+
#elif defined(__GNUC__)
17+
# pragma GCC diagnostic ignored "-Winaccessible-base"
1618
#endif
1719

1820
/*

libcxxabi/test/dynamic_cast5.pass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// This test explicitly tests dynamic cast with types that have inaccessible
1313
// bases.
1414
#if defined(__clang__)
15-
#pragma clang diagnostic ignored "-Winaccessible-base"
15+
# pragma clang diagnostic ignored "-Winaccessible-base"
16+
#elif defined(__GNUC__)
17+
# pragma GCC diagnostic ignored "-Winaccessible-base"
1618
#endif
1719

1820
namespace t1

libcxxabi/test/guard_test_basic.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include "../src/cxa_guard_impl.h"
1313
#include <cassert>
1414

15+
// Disable GCC warning about tautological comparison of a function's address
16+
#if defined(__GNUC__) && !defined(__clang__)
17+
# pragma GCC diagnostic ignored "-Waddress"
18+
#endif
19+
1520
using namespace __cxxabiv1;
1621

1722
template <class GuardType, class Impl>

libcxxabi/test/inherited_exception.pass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
//
1111
// C++ ABI 15.3:
1212
// A handler is a match for an exception object of type E if
13-
// / * The handler is of type cv T or cv T& and E and T are the same type \
14-
// | (ignoring the top-level cv-qualifiers), or |
15-
// | * the handler is of type cv T or cv T& and T is an unambiguous base |
16-
// \ class of E, or /
13+
// > * The handler is of type cv T or cv T& and E and T are the same type <
14+
// > (ignoring the top-level cv-qualifiers), or <
15+
// > * the handler is of type cv T or cv T& and T is an unambiguous base <
16+
// > class of E, or <
1717
// * the handler is of type cv1 T* cv2 and E is a pointer type that can
1818
// be converted to the type of the handler by either or both of
1919
// o a standard pointer conversion (4.10 [conv.ptr]) not involving
@@ -26,6 +26,12 @@
2626

2727
// UNSUPPORTED: no-exceptions
2828

29+
// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
30+
// by earlier handlers, which this test is exercising. We have to disable
31+
// warnings altogether to remove the error.
32+
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
33+
// ADDITIONAL_COMPILE_FLAGS: -Wno-error
34+
2935
// Clang emits warnings about exceptions of type 'Child' being caught by
3036
// an earlier handler of type 'Base'. Congrats clang, you've just
3137
// diagnosed the behavior under test.

libcxxabi/test/test_vector3.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
#include <memory>
1919

20+
// Disable warning about throw always calling terminate.
21+
#if defined(__GNUC__) && !defined(__clang__)
22+
# pragma GCC diagnostic ignored "-Wterminate"
23+
#endif
24+
2025
// use dtors instead of try/catch
2126
namespace test1 {
2227
struct B {

0 commit comments

Comments
 (0)