Skip to content

Commit

Permalink
Replace NDEBUG by [[maybe_unused]] (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jan 23, 2025
1 parent ea783ce commit c946a0f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 78 deletions.
16 changes: 2 additions & 14 deletions cpp/src/Ice/CtrlCHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,12 @@ CtrlCHandler::CtrlCHandler(CtrlCHandlerCallback callback)
sigaddset(&ctrlCLikeSignals, SIGINT);
sigaddset(&ctrlCLikeSignals, SIGTERM);

# ifndef NDEBUG
int rc = pthread_sigmask(SIG_BLOCK, &ctrlCLikeSignals, nullptr);
[[maybe_unused]] int rc = pthread_sigmask(SIG_BLOCK, &ctrlCLikeSignals, nullptr);
assert(rc == 0);

// Joinable thread
rc = pthread_create(&_tid, nullptr, sigwaitThread, nullptr);
assert(rc == 0);
# else
pthread_sigmask(SIG_BLOCK, &ctrlCLikeSignals, 0);

// Joinable thread
pthread_create(&_tid, 0, sigwaitThread, 0);
# endif
}
}

Expand All @@ -202,15 +195,10 @@ CtrlCHandler::~CtrlCHandler()
// Signal the sigwaitThread and join it.
//
void* status = nullptr;
# ifndef NDEBUG
int rc = pthread_kill(_tid, SIGTERM); // NOLINT(cert-pos44-c)
[[maybe_unused]] int rc = pthread_kill(_tid, SIGTERM); // NOLINT(cert-pos44-c)
assert(rc == 0);
rc = pthread_join(_tid, &status);
assert(rc == 0);
# else
pthread_kill(_tid, SIGTERM); // NOLINT(cert-pos44-c)
pthread_join(_tid, &status);
# endif
}

#endif
12 changes: 2 additions & 10 deletions cpp/src/Ice/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,7 @@ Ice::InputStream::EncapsDecoder10::throwException(UserExceptionFactory factory)
}

void
#ifndef NDEBUG
Ice::InputStream::EncapsDecoder10::startInstance(SliceType sliceType)
#else
Ice::InputStream::EncapsDecoder10::startInstance(SliceType)
#endif
Ice::InputStream::EncapsDecoder10::startInstance([[maybe_unused]] SliceType sliceType)
{
assert(_sliceType == sliceType);
_skipFirstSlice = true;
Expand Down Expand Up @@ -1910,11 +1906,7 @@ Ice::InputStream::EncapsDecoder11::throwException(UserExceptionFactory factory)
}

void
#ifndef NDEBUG
Ice::InputStream::EncapsDecoder11::startInstance(SliceType sliceType)
#else
Ice::InputStream::EncapsDecoder11::startInstance(SliceType)
#endif
Ice::InputStream::EncapsDecoder11::startInstance([[maybe_unused]] SliceType sliceType)
{
assert(_current->sliceType == sliceType);
_current->skipFirstSlice = true;
Expand Down
12 changes: 2 additions & 10 deletions cpp/src/Ice/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,12 +1591,8 @@ IceInternal::doBind(SOCKET fd, const Address& addr, const string&)

Address local;
auto len = static_cast<socklen_t>(sizeof(sockaddr_storage));
#ifdef NDEBUG
getsockname(fd, &local.sa, &len);
#else
int ret = getsockname(fd, &local.sa, &len);
[[maybe_unused]] int ret = getsockname(fd, &local.sa, &len);
assert(ret != SOCKET_ERROR);
#endif
return local;
}

Expand Down Expand Up @@ -1948,12 +1944,8 @@ IceInternal::createPipe(SOCKET fds[2])
try
{
setBlock(fds[0], true);
# ifndef NDEBUG
bool connected = doConnect(fds[0], addr, Address());
[[maybe_unused]] bool connected = doConnect(fds[0], addr, Address());
assert(connected);
# else
doConnect(fds[0], addr, Address());
# endif
}
catch (...)
{
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/Ice/SSL/OpenSSLTransceiverI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,7 @@ OpenSSL::TransceiverI::receive()

assert(_readBuffer.i == _readBuffer.b.end());

#ifndef NDEBUG
int n =
#endif
[[maybe_unused]] int n =
BIO_write(_memBio, &_readBuffer.b[0], static_cast<int>(_readBuffer.b.end() - _readBuffer.b.begin()));

assert(n == static_cast<int>(_readBuffer.b.end() - _readBuffer.b.begin()));
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/Ice/UndefSysMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#ifndef ICE_UNDEF_SYS_MACROS_H
#define ICE_UNDEF_SYS_MACROS_H

//
// This header includes macros that can end up being dragged into
// the generated code from system headers, such as major() or NDEBUG.
// the generated code from system headers, such as major().
// If a Slice symbol has the same name as a macro, the generated
// code most likely won't compile (but, depending how the macro is
// defined, may even compile).
Expand All @@ -18,7 +17,6 @@
//
// The #ifdef ... #endif protection is necessary to prevent
// warnings on some platforms.
//

#ifdef major
# undef major
Expand Down
12 changes: 2 additions & 10 deletions cpp/src/IceGrid/AdminCallbackRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,16 @@ AdminCallbackRouter::addMapping(const string& category, const shared_ptr<Ice::Co
{
lock_guard lock(_mutex);

#ifdef NDEBUG
_categoryToConnection.insert({category, con});
#else
bool inserted = _categoryToConnection.insert({category, con}).second;
[[maybe_unused]] bool inserted = _categoryToConnection.insert({category, con}).second;
assert(inserted == true);
#endif
}

void
AdminCallbackRouter::removeMapping(const string& category)
{
lock_guard lock(_mutex);

#ifndef NDEBUG
size_t one =
#endif
_categoryToConnection.erase(category);

[[maybe_unused]] size_t one = _categoryToConnection.erase(category);
assert(one == 1);
}

Expand Down
6 changes: 1 addition & 5 deletions cpp/test/Slice/escape/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class breakI : public cpp_and::_cpp_break
response(0);
}

#ifndef NDEBUG
void _cpp_explicit(const ::Ice::Current& current) override
#else
virtual void _cpp_explicit(const ::Ice::Current&) override
#endif
void _cpp_explicit([[maybe_unused]] const Ice::Current& current) override
{
assert(current.operation == "explicit");
}
Expand Down
4 changes: 1 addition & 3 deletions python/modules/IcePy/ObjectAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1746,9 +1746,7 @@ IcePy::wrapObjectAdapter(const Ice::ObjectAdapterPtr& adapter)
Ice::ObjectAdapterPtr
IcePy::unwrapObjectAdapter(PyObject* obj)
{
#ifndef NDEBUG
PyObject* wrapperType = lookupType("Ice.ObjectAdapter");
#endif
[[maybe_unused]] PyObject* wrapperType = lookupType("Ice.ObjectAdapter");
assert(wrapperType);
assert(PyObject_IsInstance(obj, wrapperType));
PyObjectHandle impl{getAttr(obj, "_impl", false)};
Expand Down
10 changes: 2 additions & 8 deletions python/modules/IcePy/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,7 @@ IcePy::Operation::Operation(
// metadata
//
assert(PyTuple_Check(meta));
#ifndef NDEBUG
bool b =
#endif
tupleToStringSeq(meta, metadata);
[[maybe_unused]] bool b = tupleToStringSeq(meta, metadata);
assert(b);

//
Expand Down Expand Up @@ -972,10 +969,7 @@ IcePy::Operation::convertParam(PyObject* p, Py_ssize_t pos)
//
PyObject* meta = PyTuple_GET_ITEM(p, 0);
assert(PyTuple_Check(meta));
#ifndef NDEBUG
bool b =
#endif
tupleToStringSeq(meta, param->metadata);
[[maybe_unused]] bool b = tupleToStringSeq(meta, param->metadata);
assert(b);

//
Expand Down
10 changes: 2 additions & 8 deletions python/modules/IcePy/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,7 @@ convertDataMembers(PyObject* members, DataMemberList& reqMembers, DataMemberList

DataMemberPtr member = make_shared<DataMember>();
member->name = getString(name);
#ifndef NDEBUG
bool b =
#endif
tupleToStringSeq(meta, member->metadata);
[[maybe_unused]] bool b = tupleToStringSeq(meta, member->metadata);
assert(b);
member->type = getType(t);
if (allowOptional)
Expand Down Expand Up @@ -1372,10 +1369,7 @@ IcePy::SequenceInfo::SequenceInfo(string ident, PyObject* m, PyObject* t) : id(s
assert(PyTuple_Check(m));

vector<string> metadata;
#ifndef NDEBUG
bool b =
#endif
tupleToStringSeq(m, metadata);
[[maybe_unused]] bool b = tupleToStringSeq(m, metadata);
assert(b);

const_cast<SequenceMappingPtr&>(mapping) = make_shared<SequenceMapping>(metadata);
Expand Down
5 changes: 1 addition & 4 deletions ruby/src/IceRuby/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,7 @@ checkedCastImpl(const Ice::ObjectPrx& p, const string& id, VALUE facet, VALUE ct
else
{
Ice::Context c;
#ifndef NDEBUG
bool b =
#endif
hashToContext(ctx, c);
[[maybe_unused]] bool b = hashToContext(ctx, c);
assert(b);

if (target->ice_isA(id, c))
Expand Down

0 comments on commit c946a0f

Please sign in to comment.