https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98305

            Bug ID: 98305
           Summary: Incomprehensible -Wmismatched-new-delete warning
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

With recent GCC 11 trunk (at git commit
8dede2411195eb2fd672d8d0c758f94732bd6d77):

> $ cat test.cc
> #include <cstddef>
> template<typename> struct Reference {};
> template<typename> struct S2 {
>   static void * operator new(std::size_t);
>   static void operator delete(void *);
>   S2();
> };
> void f() { new S2<Reference<int>>; }

> $ g++ -Wmismatched-new-delete -c test.cc
> test.cc: In function ‘void f()’:
> test.cc:8:16: warning: ‘static void S2< <template-parameter-1-1> >::operator 
> delete(void*) [with <template-parameter-1-1> = Reference<int>]’ called on 
> pointer returned from a mismatched allocation function 
> [-Wmismatched-new-delete]
>     8 | void f() { new S2<Reference<int>>; }
>       |                ^~~~~~~~~~~~~~~~~~
> test.cc:8:16: note: returned from ‘static void* S2< <template-parameter-1-1> 
> >::operator new(std::size_t) [with <template-parameter-1-1> = Reference<int>]’

(And oddly enough, the warning disappears when Reference is renamed to e.g.
S1.)

Reply via email to