Skip to content

Commit fe4d1a4

Browse files
Jeffrey MendelsohnGitHub Enterprise
authored andcommitted
reduce clang-15 warnings (#4840)
* reduce clang-15 warnings * update bslmf_invokeresult_cpp03.00.t.cpp * correct warnings
1 parent 3b41356 commit fe4d1a4

Some content is hidden

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

43 files changed

+222
-73
lines changed

groups/bsl/bslalg/bslalg_arrayprimitives.t.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ char getValue(const Uint64& u64)
630630

631631
void setValue(float *pf, char ch)
632632
{
633-
*pf = static_cast<int>(ch);
633+
*pf = static_cast<short>(ch);
634634
}
635635

636636
void setValue(double *pf, char ch)

groups/bsl/bslalg/bslalg_autoarraydestructor.t.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ class TestType;
109109
typedef TestType T; // uses 'bslma' allocators
110110

111111
// STATIC DATA
112-
const int MAX_ALIGN = bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT;
113-
114112
static int numDefaultCtorCalls = 0;
115113
static int numCharCtorCalls = 0;
116114
static int numCopyCtorCalls = 0;

groups/bsl/bslalg/bslalg_constructorproxy.t.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class TestType_Base {
300300
// ACCESSORS
301301
allocator_type get_allocator() const { return d_allocator; }
302302

303-
bool matchAllocator(const AllocArg a) const { return a == d_allocator; }
303+
bool matchAllocator(AllocArg a) const { return a == d_allocator; }
304304
bool matchAllocator(bslma::Allocator *a) const
305305
// Return 'true' if the specified 'a' matches the allocator. The
306306
// second overload relies on the fact that most STL allocators used for

groups/bsl/bslalg/bslalg_containerbase.t.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// bslalg_containerbase.t.cpp -*-C++-*-
22
#include <bslalg_containerbase.h>
33

4+
#include <bsla_maybeunused.h>
5+
46
#include <bslma_allocator.h>
57
#include <bslma_allocatorutil.h>
68
#include <bslma_autodestructor.h>
@@ -198,7 +200,8 @@ class StatelessSTLAllocator {
198200
}
199201

200202
void deallocate(value_type *p, std::size_t n) {
201-
bslma::Allocator *rsrc = bslma::Default::defaultAllocator();
203+
BSLA_MAYBE_UNUSED bslma::Allocator *rsrc =
204+
bslma::Default::defaultAllocator();
202205
bslma::AllocatorUtil::deallocateObject(&g_StatelessSTLAllocatorRsrc,
203206
p, n);
204207
}

groups/bsl/bslalg/bslalg_dequeprimitives.t.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,20 @@ class TestDeque : public TestDeque_Type<ALLOCATOR>::AllocatorType
310310
for (int i = 0; i < d_blockNum; ++i) {
311311
size_type numMaxAlignedType =
312312
(sizeof(Block) + MAX_ALIGN - 1) / MAX_ALIGN;
313-
AllocatorTraits::deallocate(allocator(),
314-
(bsls::AlignmentUtil::MaxAlignedType *) d_blocks_p[i],
315-
numMaxAlignedType);
313+
AllocatorTraits::deallocate(
314+
allocator(),
315+
(bsls::AlignmentUtil::MaxAlignedType *)static_cast<void *>(
316+
d_blocks_p[i]),
317+
numMaxAlignedType);
316318
}
317319
size_type numBytes = static_cast<size_type>(sizeof(BlockPtr))
318320
+ d_blockNum;
319321
size_type numMaxAlignedType = (numBytes + MAX_ALIGN - 1) / MAX_ALIGN;
320-
AllocatorTraits::deallocate(allocator(),
321-
(bsls::AlignmentUtil::MaxAlignedType *) d_blocks_p,
322-
numMaxAlignedType);
322+
AllocatorTraits::deallocate(
323+
allocator(),
324+
(bsls::AlignmentUtil::MaxAlignedType *)static_cast<void *>(
325+
d_blocks_p),
326+
numMaxAlignedType);
323327
}
324328

325329
// MANIPULATORS

groups/bsl/bslalg/bslalg_rangecompare.t.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,8 @@ void timeEqualAlgorithm(const char *typeName,
19571957
printf("\n\tcompare with '%s'\n", typeName);
19581958
{
19591959
const size_t bufferSize = rawBufferSize / sizeof(TYPE);
1960-
TYPE *buffer1 = (TYPE*)rawBuffer1;
1961-
TYPE *buffer2 = (TYPE*)rawBuffer2;
1960+
TYPE *buffer1 = (TYPE*)static_cast<void *>(rawBuffer1);
1961+
TYPE *buffer2 = (TYPE*)static_cast<void *>(rawBuffer2);
19621962

19631963
for (size_t j = 0; j < bufferSize; ++j) {
19641964
buffer1[j] = buffer2[j] = TYPE();
@@ -2031,8 +2031,8 @@ void timeLexicographicalAlgorithm(const char *typeName,
20312031
printf("\n\tcompare with '%s'\n", typeName);
20322032
{
20332033
const size_t bufferSize = rawBufferSize / sizeof(TYPE);
2034-
TYPE *buffer1 = (TYPE*)rawBuffer1;
2035-
TYPE *buffer2 = (TYPE*)rawBuffer2;
2034+
TYPE *buffer1 = (TYPE*)static_cast<void *>(rawBuffer1);
2035+
TYPE *buffer2 = (TYPE*)static_cast<void *>(rawBuffer2);
20362036

20372037
for (size_t j = 0; j < bufferSize; ++j) {
20382038
buffer1[j] = buffer2[j] = TYPE();

groups/bsl/bslalg/bslalg_selecttrait.t.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <bslalg_typetraitpair.h> // for testing only
1010
#include <bslalg_typetraitusesbslmaallocator.h> // for testing only
1111

12+
#include <bsla_maybeunused.h>
13+
1214
#include <bslma_usesbslmaallocator.h>
1315

1416
#include <bslmf_isbitwisemoveable.h>
@@ -103,9 +105,10 @@ const unsigned TRAIT_HASSTLITERATORS = 0x0040;
103105
const unsigned TRAIT_HASPOINTERSEMANTICS = 0x0080;
104106

105107
// Traits group
106-
const unsigned TRAIT_POD = (TRAIT_BITWISEMOVEABLE |
107-
TRAIT_BITWISECOPYABLE |
108-
TRAIT_HASTRIVIALDEFAULTCONSTRUCTOR);
108+
BSLA_MAYBE_UNUSED const unsigned TRAIT_POD =
109+
(TRAIT_BITWISEMOVEABLE |
110+
TRAIT_BITWISECOPYABLE |
111+
TRAIT_HASTRIVIALDEFAULTCONSTRUCTOR);
109112

110113
template <class TYPE>
111114
unsigned traitBits()

groups/bsl/bslalg/bslalg_typetraitbitwisecopyable.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
#include <bslalg_hastrait.h>
66

77
#include <bsls_bsltestutil.h>
8+
#include <bsls_platform.h>
89

910
#include <stdio.h> // 'printf'
1011
#include <stdlib.h> // 'atoi'
1112

1213
using namespace BloombergLP;
1314

15+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
16+
#ifdef BSLS_PLATFORM_CMP_CLANG
17+
#pragma GCC diagnostic ignored "-Wunused-private-field"
18+
#endif
19+
#endif
20+
1421
//=============================================================================
1522
// TEST PLAN
1623
//-----------------------------------------------------------------------------

groups/bsl/bslalg/bslalg_typetraitbitwiseequalitycomparable.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
#include <bslalg_hastrait.h>
66

77
#include <bsls_bsltestutil.h>
8+
#include <bsls_platform.h>
89

910
#include <stdio.h> // 'printf'
1011
#include <stdlib.h> // 'atoi'
1112

1213
using namespace BloombergLP;
1314

15+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
16+
#ifdef BSLS_PLATFORM_CMP_CLANG
17+
#pragma GCC diagnostic ignored "-Wunused-private-field"
18+
#endif
19+
#endif
20+
1421
//=============================================================================
1522
// TEST PLAN
1623
//-----------------------------------------------------------------------------

groups/bsl/bslalg/bslalg_typetraitbitwisemoveable.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
#include <bslalg_hastrait.h>
66

77
#include <bsls_bsltestutil.h>
8+
#include <bsls_platform.h>
89

910
#include <stdio.h> // 'printf'
1011
#include <stdlib.h> // 'atoi'
1112

1213
using namespace BloombergLP;
1314

15+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
16+
#ifdef BSLS_PLATFORM_CMP_CLANG
17+
#pragma GCC diagnostic ignored "-Wunused-private-field"
18+
#endif
19+
#endif
20+
1421
//=============================================================================
1522
// TEST PLAN
1623
//-----------------------------------------------------------------------------

groups/bsl/bslalg/bslalg_typetraithastrivialdefaultconstructor.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
#include <bslalg_hastrait.h>
66

77
#include <bsls_bsltestutil.h>
8+
#include <bsls_platform.h>
89

910
#include <stdio.h> // 'printf'
1011
#include <stdlib.h> // 'atoi'
1112

1213
using namespace BloombergLP;
1314

15+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
16+
#ifdef BSLS_PLATFORM_CMP_CLANG
17+
#pragma GCC diagnostic ignored "-Wunused-private-field"
18+
#endif
19+
#endif
20+
1421
//=============================================================================
1522
// TEST PLAN
1623
//-----------------------------------------------------------------------------

groups/bsl/bslh/bslh_seededhash.t.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ bool TypeChecker<EXPECTED_TYPE>::isCorrectType(EXPECTED_TYPE) {
337337

338338
template<class EXPECTED_TYPE>
339339
template<class BDE_OTHER_TYPE>
340-
bool TypeChecker<EXPECTED_TYPE>::isCorrectType(BDE_OTHER_TYPE type) {
340+
bool TypeChecker<EXPECTED_TYPE>::isCorrectType(BDE_OTHER_TYPE /* type */) {
341341
return false;
342342
}
343343

groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp

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

224224
using namespace BloombergLP;
225225

226+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
227+
#ifdef BSLS_PLATFORM_CMP_CLANG
228+
#pragma GCC diagnostic ignored "-Wunused-private-field"
229+
#endif
230+
#endif
231+
226232
//=============================================================================
227233
// TEST PLAN
228234
//-----------------------------------------------------------------------------

groups/bsl/bslma/bslma_allocator.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <bsls_alignmentutil.h>
77
#include <bsls_bsltestutil.h>
88
#include <bsls_compilerfeatures.h>
9+
#include <bsls_platform.h>
910
#include <bsls_protocoltest.h>
1011

1112
#include <stdio.h> // 'printf'
@@ -16,6 +17,12 @@
1617

1718
using namespace BloombergLP;
1819

20+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
21+
#ifdef BSLS_PLATFORM_CMP_CLANG
22+
#pragma GCC diagnostic ignored "-Wunused-private-field"
23+
#endif
24+
#endif
25+
1926
//=============================================================================
2027
// TEST PLAN
2128
//-----------------------------------------------------------------------------

groups/bsl/bslma/bslma_deleterhelper.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <bsls_assert.h>
77
#include <bsls_asserttest.h>
88
#include <bsls_bsltestutil.h>
9+
#include <bsls_platform.h>
910

1011
#include <stdio.h> // 'printf'
1112
#include <stdlib.h> // 'atoi'
@@ -14,6 +15,12 @@
1415

1516
using namespace BloombergLP;
1617

18+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
19+
#ifdef BSLS_PLATFORM_CMP_CLANG
20+
#pragma GCC diagnostic ignored "-Wunused-private-field"
21+
#endif
22+
#endif
23+
1724
//=============================================================================
1825
// TEST PLAN
1926
//-----------------------------------------------------------------------------

groups/bsl/bslma/bslma_managedallocator.t.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,16 @@ void * LinkedListMA::allocate(size_type size)
245245
// If we got here, there were no blocks that could satisfy the requirement.
246246
// Get truly new memory.
247247
char *newMem = new char[sizeof(Node) + size];
248-
((Node *)newMem)->d_dataSize = size;
249-
((Node *)newMem)->d_next = d_usedList;
250-
d_usedList = (Node *)newMem;
248+
((Node *)static_cast<void *>(newMem))->d_dataSize = size;
249+
((Node *)static_cast<void *>(newMem))->d_next = d_usedList;
250+
d_usedList = (Node *)static_cast<void *>(newMem);
251251

252252
return newMem + DATAOFFSET;
253253
}
254254

255255
void LinkedListMA::deallocate(void *address)
256256
{
257-
changeLists((Node *)((char *)address - DATAOFFSET),
257+
changeLists((Node *)static_cast<void *>((char *)address - DATAOFFSET),
258258
&d_usedList, &d_freeList);
259259
}
260260

@@ -515,10 +515,9 @@ int main(int argc, char *argv[])
515515
// --------------------------------------------------------------------
516516

517517
const char *sampleStrings[] = {
518-
"Hello", "How are you?", "Es geht mir gut",
519-
"Porque tenemos que trabajar?", "Donde esta el gatito?",
520-
"You get a shiver in the dark/it's raining in the "
521-
"park/but meantime"
518+
"Hello", "How are you?", "Es geht mir gut",
519+
"Porque tenemos que trabajar?", "Donde esta el gatito?",
520+
"You get a shiver in the dark/it's raining in the park/but meantime"
522521
};
523522

524523
const int NUMBER_OF_STRINGS =

groups/bsl/bslma/bslma_sequentialpool.t.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,7 @@ int main(int argc, char *argv[])
14411441
blockSize(INITIAL_SIZE * 2) == tc.numBytesInUse());
14421442
}
14431443
else {
1444-
int nextSize = calculateNextSize(abs(INITIAL_SIZE),
1445-
SIZE);
1444+
int nextSize = calculateNextSize(INITIAL_SIZE, SIZE);
14461445
LOOP4_ASSERT(i, SIZE, blockSize(nextSize),
14471446
ta.numBytesInUse(),
14481447
blockSize(nextSize) == ta.numBytesInUse());

groups/bsl/bslma/bslma_sharedptroutofplacerep.t.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <bsls_asserttest.h>
1313
#include <bsls_bsltestutil.h>
14+
#include <bsls_platform.h>
1415

1516
#include <cstddef> // std::size_t
1617

@@ -31,6 +32,12 @@
3132

3233
using namespace BloombergLP;
3334

35+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
36+
#ifdef BSLS_PLATFORM_CMP_CLANG
37+
#pragma GCC diagnostic ignored "-Wunused-private-field"
38+
#endif
39+
#endif
40+
3441
//=============================================================================
3542
// TEST PLAN
3643
//-----------------------------------------------------------------------------

groups/bsl/bslma/bslma_testallocator.t.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,8 @@ int main(int argc, char *argv[])
24172417
if (verbose) printf(
24182418
"\t[deallocate pointer + sizeof(size_type)]\n");
24192419
if (veryVerbose) puts(LINE);
2420-
a.deallocate((bslma::Allocator::size_type *)p + 1);
2420+
a.deallocate((bslma::Allocator::size_type *)
2421+
static_cast<void *>(p) + 1);
24212422
if (veryVerbose) puts(LINE);
24222423
ASSERT(1 == a.numBlocksInUse());
24232424
ASSERT(3 == a.numBytesInUse());
@@ -2428,7 +2429,8 @@ int main(int argc, char *argv[])
24282429
if (verbose) printf(
24292430
"\t[deallocate pointer - sizeof(size_type)]\n");
24302431
if (veryVerbose) puts(LINE);
2431-
a.deallocate((bslma::Allocator::size_type *)p - 1);
2432+
a.deallocate((bslma::Allocator::size_type *)
2433+
static_cast<void *>(p) - 1);
24322434
if (veryVerbose) puts(LINE);
24332435
ASSERT(1 == a.numBlocksInUse());
24342436
ASSERT(3 == a.numBytesInUse());

groups/bsl/bslmf/bslmf_forwardingreftype.t.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ using namespace BloombergLP;
4040
#pragma error_messages(off, SEC_UNINITIALIZED_MEM_READ)
4141
#endif
4242

43+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
44+
#ifdef BSLS_PLATFORM_CMP_CLANG
45+
#pragma GCC diagnostic ignored "-Wdeprecated-volatile"
46+
#endif
47+
#endif
48+
4349
// Suppress bde_verify messages about all-uppercase type names. Test drivers
4450
// are rife with short names like 'F' or 'PF' or 'T' or 'T1'.
4551

groups/bsl/bslmf/bslmf_forwardingtype.t.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ using namespace BloombergLP;
3737
#pragma error_messages(off, SEC_UNINITIALIZED_MEM_READ)
3838
#endif
3939

40+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
41+
#ifdef BSLS_PLATFORM_CMP_CLANG
42+
#pragma GCC diagnostic ignored "-Wdeprecated-volatile"
43+
#endif
44+
#endif
45+
4046
// Suppress bde_verify messages about all-uppercase type names. Test drivers
4147
// are rife with short names like 'F' or 'PF' or 'T' or 'T1'.
4248

groups/bsl/bslmf/bslmf_invokeresult.00.t.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
# pragma error_messages(off, functypequal)
5252
#endif
5353

54+
#ifdef BSLS_PLATFORM_HAS_PRAGMA_GCC_DIAGNOSTIC
55+
#ifdef BSLS_PLATFORM_CMP_CLANG
56+
#pragma GCC diagnostic ignored "-Wdeprecated-volatile"
57+
#endif
58+
#endif
5459

5560
using namespace BloombergLP;
5661

0 commit comments

Comments
 (0)