https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107527
Bug ID: 107527
Summary: warning: declaration of ‘void operator delete(void*,
std::size_t)’ has a different exception specifier
[-Wsystem-headers]
Product: gcc
Version: 12.2.1
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
This code compiles cleanly unless you use -Wsystem-headers:
#include <new>
#include <cstdlib>
void* operator new(std::size_t n)
{
return std::malloc(n);
}
void operator delete(void* p)
{
std::free(p);
}
void operator delete(void* p, std::size_t)
{
std::free(p);
}
$ g++ del.C -c
$ g++ del.C -c -Wsystem-headers
del.C:9:6: warning: declaration of ‘void operator delete(void*)’ has a
different exception specifier [-Wsystem-headers]
9 | void operator delete(void* p)
| ^~~~~~~~
In file included from del.C:1:
/usr/include/c++/12/new:130:6: note: from previous declaration ‘void operator
delete(void*) noexcept’
130 | void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
del.C:14:6: warning: declaration of ‘void operator delete(void*, std::size_t)’
has a different exception specifier [-Wsystem-headers]
14 | void operator delete(void* p, std::size_t)
| ^~~~~~~~
/usr/include/c++/12/new:135:6: note: from previous declaration ‘void operator
delete(void*, std::size_t) noexcept’
135 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
But the warning is correct, and indicates a problem in the user code. It should
not be suppressed by the system header.