Bug 107527 - warning: declaration of ‘void operator delete(void*, std::size_t)’ has a different exception specifier [-Wsystem-headers]
Summary: warning: declaration of ‘void operator delete(void*, std::size_t)’ has a diff...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2022-11-04 21:30 UTC by Jonathan Wakely
Modified: 2022-11-05 08:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2022-11-04 21:30:21 UTC
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.
Comment 1 Andrew Pinski 2022-11-04 21:34:59 UTC
I thought I had saw this one before. Specifically something related to Darwin.