public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
@ 2022-03-01  7:48 周春明(日月)
  2022-03-01 14:32 ` Simon Marchi
  2022-03-02 16:30 ` ../../gdbsupport/new-op.cc:137:1: " Andrew Burgess
  0 siblings, 2 replies; 13+ messages in thread
From: 周春明(日月) @ 2022-03-01  7:48 UTC (permalink / raw)
  To: Gdb-patches, Simon Marchi, gdb-patches
  Cc: Louis-He, Dominique Quatravaux, Sam Warner


Hi GDB maintainers,

I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!

 CXX new-op.o
../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
 extern void operator delete (void *p, std::size_t) noexcept;
 ^
../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
 extern void operator delete[] (void *p, std::size_t) noexcept;
 ^
../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
 operator delete (void *p, std::size_t) noexcept
 ^
../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
 operator delete[] (void *p, std::size_t) noexcept

------------------------------------------------------------------
发件人:Philippe Blain via Gdb-patches <gdb-patches@sourceware.org>
发送时间:2022年3月1日(星期二) 02:41
收件人:Simon Marchi <simon.marchi@polymtl.ca>; gdb-patches <gdb-patches@sourceware.org>
抄 送:Louis-He <1726110778@qq.com>; Dominique Quatravaux <dominique.quatravaux@epfl.ch>; Sam Warner <samuel.r.warner@me.com>
主 题:Re: [RFC][PATCH v3 1/1][PR gdb/24069] gdb/darwin: skip over WIFSTOPPED wait4 status



Le 2022-02-28 à 13:34, Simon Marchi a écrit :
> 
> 
> On 2022-02-28 12:52, Philippe Blain wrote:
>> Hi Simon,
>>
>> Le 2022-02-24 à 10:49, Simon Marchi a écrit :
>>>
>>>
>>> On 2022-02-24 09:23, Philippe Blain wrote:
>>>> From: Dominique Quatravaux <dominique.quatravaux@epfl.ch>
>>>>>
>>>>
>>>>  PR gdb/24609
>>>>  * gdb/darwin-nat.c (darwin_nat_target::decode_message): Also
>>>>  check for WIFSTOPPED upon MACH_NOTIFY_DEAD_NAME.
>>>
>>> Thanks, pushed.
>>>
>>> Simon
>>>
>>
>> I noticed that the Bugzilla entry was not updated when you pushed
>> that commit, whereas it was for the previous one [1]. I'm not sure
>> of what is the automation that makes this work...
>>
>> I thought it was because my changelog entry mistakenly used 24609 instead
>> of 24069, but that was the case also for v2 1/2, so I guess that's not
>> the cause...
> 
> Patch #1 had a link to the correct bugzilla ticket in its commit message,
> so the connection was made.
> 
> Patch #2 didn't have any mention of the bugzilla ticket, so there was
> no connection.
> 
> The correct thing to do nowadays, according to our standard procedures,
> would have been to use the:
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24069
> 
> trailer.  But I often forget about it.
> 
> Simon

Noted. I just checked the ContributionChecklist page and
see you've updated it, thanks :)

Philippe.

[1] https://sourceware.org/gdb/wiki/ContributionChecklist#Properly_formatted_commit_messages

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-01  7:48 ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] 周春明(日月)
@ 2022-03-01 14:32 ` Simon Marchi
  2022-03-02  3:08   ` 回复:../../gdbsupport/new-op.cc:137:1: " 周春明(日月)
  2022-03-02 16:30 ` ../../gdbsupport/new-op.cc:137:1: " Andrew Burgess
  1 sibling, 1 reply; 13+ messages in thread
From: Simon Marchi @ 2022-03-01 14:32 UTC (permalink / raw)
  To: 周春明(日月), Gdb-patches, gdb-patches
  Cc: Louis-He, Dominique Quatravaux, Sam Warner



On 2022-03-01 02:48, 周春明(日月) wrote:
> 
> Hi GDB maintainers,
> 
> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
> 
>   CXX      new-op.o
> 
> *../../gdbsupport/new-op.cc:32:13:* *error: *‘*void operator delete(void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  extern void operator delete (void *p, std::size_t) noexcept;
> 
> *             ^*
> 
> *../../gdbsupport/new-op.cc:33:13:* *error: *‘*void operator delete [](void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  extern void operator delete[] (void *p, std::size_t) noexcept;
> 
> *             ^*
> 
> *../../gdbsupport/new-op.cc:119:1:* *error: *‘*void operator delete(void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  operator delete (void *p, std::size_t) noexcept
> 
> * ^*
> 
> *../../gdbsupport/new-op.cc:137:1:* *error: *‘*void operator delete [](void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  operator delete[] (void *p, std::size_t) noexcept

Hi,

Can you give a bit more info?

 - compiler and compiler version
 - OS and OS version
 - your complete configure line
 - the build command line for that file, given by "make V=1"

Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

* 回复:../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-01 14:32 ` Simon Marchi
@ 2022-03-02  3:08   ` 周春明(日月)
  2022-03-02 16:45     ` Simon Marchi
  0 siblings, 1 reply; 13+ messages in thread
From: 周春明(日月) @ 2022-03-02  3:08 UTC (permalink / raw)
  To: Simon Marchi, Gdb-patches, gdb-patches
  Cc: Louis-He, Dominique Quatravaux, Sam Warner







------------------------------------------------------------------
发件人:Simon Marchi <simon.marchi@polymtl.ca>
发送时间:2022年3月1日(星期二) 22:32
收件人:周春明(日月) <riyue.zcm@alibaba-inc.com>; Gdb-patches <gdb-patches-bounces+riyue.zcm=alibaba-inc.com@sourceware.org>; gdb-patches <gdb-patches@sourceware.org>
抄 送:Louis-He <1726110778@qq.com>; Dominique Quatravaux <dominique.quatravaux@epfl.ch>; Sam Warner <samuel.r.warner@me.com>
主 题:Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]



On 2022-03-01 02:48, 周春明(日月) wrote:
> 
> Hi GDB maintainers,
> 
> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
> 
>   CXX      new-op.o
> 
> *../../gdbsupport/new-op.cc:32:13:* *error: *‘*void operator delete(void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  extern void operator delete (void *p, std::size_t) noexcept;
> 
> *             ^*
> 
> *../../gdbsupport/new-op.cc:33:13:* *error: *‘*void operator delete [](void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  extern void operator delete[] (void *p, std::size_t) noexcept;
> 
> *             ^*
> 
> *../../gdbsupport/new-op.cc:119:1:* *error: *‘*void operator delete(void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  operator delete (void *p, std::size_t) noexcept
> 
> * ^*
> 
> *../../gdbsupport/new-op.cc:137:1:* *error: *‘*void operator delete [](void*, std::size_t)*’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
> 
>  operator delete[] (void *p, std::size_t) noexcept

Hi,

Can you give a bit more info?
[David] of course.

 - compiler and compiler version
[David] 
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609

 - OS and OS version
[David]
16.04.1-Ubuntu

 - your complete configure line
[David]
../configure --enable-64-bit-bfd --enable-targets="x86_64-linux-gnu,alippu-unknown-unknown"  --disable-ld --disable-gas --disable-gdbserver --disable-sim --enable-tui  --disable-gdbtk --disable-shared --with-expat --with-system-zlib  --without-guile --with-lzma --with-python=python3

 - the build command line for that file, given by "make V=1"
[David]
g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I../../gdbsupport -I../../gdbsupport/../include -I../../gdbsupport/../gdb -I../gnulib/import -I../../gdbsupport/../gnulib/import -I.. -I../../gdbsupport/.. -I../bfd -I../../gdbsupport/../bfd  -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wsuggest-override -Wmissing-declarations -Wstrict-null-sentinel -Wformat -Wformat-nonliteral -Werror -g -O2  -MT new-op.o -MD -MP -MF .deps/new-op.Tpo -c -o new-op.o ../../gdbsupport/new-op.cc

Thanks,
-David

Simon


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-01  7:48 ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] 周春明(日月)
  2022-03-01 14:32 ` Simon Marchi
@ 2022-03-02 16:30 ` Andrew Burgess
  2022-03-02 16:54   ` Simon Marchi
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Burgess @ 2022-03-02 16:30 UTC (permalink / raw)
  To: 周春明(日月)
  Cc: Gdb-patches, Simon Marchi, gdb-patches, Louis-He,
	Dominique Quatravaux, Sam Warner

* 周春明(日月) via Gdb-patches <gdb-patches@sourceware.org> [2022-03-01 15:48:47 +0800]:

> 
> Hi GDB maintainers,
> 
> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
> 
>  CXX new-op.o
> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>  extern void operator delete (void *p, std::size_t) noexcept;
>  ^
> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>  extern void operator delete[] (void *p, std::size_t) noexcept;
>  ^
> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>  operator delete (void *p, std::size_t) noexcept
>  ^
> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>  operator delete[] (void *p, std::size_t) noexcept

I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0.
I was unable to easily rebuild GCC 5.4.0 on my current development
machine to check if this is reproducible with upstream gcc, or is just
something impacting Ubuntu.  However, you can configure like:

  ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat"

to disable this warning/error which I believe should be fine.

For why this error is occurring, I'm honestly not 100% sure what the
error is telling us.  I _think_ what it's saying is that the delete
operator that we're declaring/defining conflicts with a "usual
deallocation function", which is added in c++14 and means something
specific.  I guess the idea is that maybe we're just randomly defining
this version of delete for some reason, and then, if/when we move on
to c++14 this function will get called unexpectedly by the language
runtime in some situations.

As time moved on I think this warning was relaxed, possibly with this
commit:

  https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html

All this makes me wonder if the usual deallocation functions are ever
actually used, and indeed, I applied the patch below, and GDB still
seems to build fine, so this might be an alternative approach.  Maybe
we should commit this to master?

Thanks,
Andrew

---

diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
index 1d066ba..4faa557 100644
--- a/gdbsupport/new-op.cc
+++ b/gdbsupport/new-op.cc
@@ -27,11 +27,6 @@
 #include "host-defs.h"
 #include <new>
 
-/* These are declared in <new> starting C++14.  Add these here to enable
-   compilation using C++11. */
-extern void operator delete (void *p, std::size_t) noexcept;
-extern void operator delete[] (void *p, std::size_t) noexcept;
-
 /* Override operator new / operator new[], in order to internal_error
    on allocation failure and thus query the user for abort/core
    dump/continue, just like xmalloc does.  We don't do this from a
@@ -116,12 +111,6 @@ operator delete (void *p, const std::nothrow_t&) noexcept
 }
 
 void
-operator delete (void *p, std::size_t) noexcept
-{
-  return ::operator delete (p, std::nothrow);
-}
-
-void
 operator delete[] (void *p) noexcept
 {
   return ::operator delete (p);
@@ -133,10 +122,4 @@ operator delete[] (void *p, const std::nothrow_t&) noexcept
   return ::operator delete (p, std::nothrow);
 }
 
-void
-operator delete[] (void *p, std::size_t) noexcept
-{
-  return ::operator delete[] (p, std::nothrow);
-}
-
 #endif


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: 回复:../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02  3:08   ` 回复:../../gdbsupport/new-op.cc:137:1: " 周春明(日月)
@ 2022-03-02 16:45     ` Simon Marchi
  0 siblings, 0 replies; 13+ messages in thread
From: Simon Marchi @ 2022-03-02 16:45 UTC (permalink / raw)
  To: 周春明(日月), Gdb-patches, gdb-patches
  Cc: Louis-He, Dominique Quatravaux, Sam Warner


> Hi,
> 
> Can you give a bit more info?
> [David] of course.
> 
> - compiler and compiler version
> [David] 
> 
> gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
> 
> 
> - OS and OS version
> [David]
> 
> 16.04.1-Ubuntu
> 
> 
> - your complete configure line
> [David]
> 
> ../configure --enable-64-bit-bfd --enable-targets="x86_64-linux-gnu,alippu-unknown-unknown"   --disable-ld --disable-gas --disable-gdbserver --disable-sim --enable-tui   --disable-gdbtk --disable-shared --with-expat --with-system-zlib   --without-guile --with-lzma --with-python=python3
> 
> 
> - the build command line for that file, given by "make V=1"
> [David]
> 
> g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I../../gdbsupport  -I../../gdbsupport/../include -I../../gdbsupport/../gdb -I../gnulib/import -I../../gdbsupport/../gnulib/import -I.. -I../../gdbsupport/..  -I../bfd -I../../gdbsupport/../bfd   -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wsuggest-override -Wmissing-declarations -Wstrict-null-sentinel -Wformat -Wformat-nonliteral -Werror -g -O2     -MT new-op.o -MD -MP -MF .deps/new-op.Tpo -c -o new-op.o ../../gdbsupport/new-op.cc

Thanks, it seems like Andrew managed to reproduce the problem with this
information, I'll reply to his message.

Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 16:30 ` ../../gdbsupport/new-op.cc:137:1: " Andrew Burgess
@ 2022-03-02 16:54   ` Simon Marchi
  2022-03-02 17:03     ` Pedro Alves
  2022-03-02 17:22     ` Andrew Burgess
  0 siblings, 2 replies; 13+ messages in thread
From: Simon Marchi @ 2022-03-02 16:54 UTC (permalink / raw)
  To: Andrew Burgess, 周春明(日月)
  Cc: Gdb-patches, gdb-patches, Louis-He, Dominique Quatravaux, Sam Warner



On 2022-03-02 11:30, Andrew Burgess wrote:
> * 周春明(日月) via Gdb-patches <gdb-patches@sourceware.org> [2022-03-01 15:48:47 +0800]:
> 
>>
>> Hi GDB maintainers,
>>
>> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
>>
>>  CXX new-op.o
>> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>  extern void operator delete (void *p, std::size_t) noexcept;
>>  ^
>> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>  extern void operator delete[] (void *p, std::size_t) noexcept;
>>  ^
>> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>  operator delete (void *p, std::size_t) noexcept
>>  ^
>> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>  operator delete[] (void *p, std::size_t) noexcept
> 
> I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0.
> I was unable to easily rebuild GCC 5.4.0 on my current development
> machine to check if this is reproducible with upstream gcc, or is just
> something impacting Ubuntu.  However, you can configure like:
> 
>   ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat"
> 
> to disable this warning/error which I believe should be fine.
> 
> For why this error is occurring, I'm honestly not 100% sure what the
> error is telling us.  I _think_ what it's saying is that the delete
> operator that we're declaring/defining conflicts with a "usual
> deallocation function", which is added in c++14 and means something
> specific.  I guess the idea is that maybe we're just randomly defining
> this version of delete for some reason, and then, if/when we move on
> to c++14 this function will get called unexpectedly by the language
> runtime in some situations.
> 
> As time moved on I think this warning was relaxed, possibly with this
> commit:
> 
>   https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html
> 
> All this makes me wonder if the usual deallocation functions are ever
> actually used, and indeed, I applied the patch below, and GDB still
> seems to build fine, so this might be an alternative approach.  Maybe
> we should commit this to master?
> 
> Thanks,
> Andrew
> 
> ---
> 
> diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
> index 1d066ba..4faa557 100644
> --- a/gdbsupport/new-op.cc
> +++ b/gdbsupport/new-op.cc
> @@ -27,11 +27,6 @@
>  #include "host-defs.h"
>  #include <new>
>  
> -/* These are declared in <new> starting C++14.  Add these here to enable
> -   compilation using C++11. */
> -extern void operator delete (void *p, std::size_t) noexcept;
> -extern void operator delete[] (void *p, std::size_t) noexcept;

The story of this is that ASan gave some alloc-dealloc mismatch warnings
if we didn't define these specific delete operators, so we defined them
in this commit:

  https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1

But for the variants of delete that are only introduced in C++14, it
meant adding functions without an equivalent declaration when building
in C++11, which produced some -Wmissing-declarations warnings.  So these
declarations were added in this commit:

  https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdead1db23eddc4fd654305

The idea being that in C++11, these delete operators won't get used, but
there will be a declaration to avoid the warning, and in C++14 the
declarations will duplicate those found in headers, which is harmless.

And now here we are, we have a C++11 compiler that complains about
declaring these delete operators.

So we can't simply remove the declarations and / or definitions, we
would just re-introduce the problems fixed by these commits.

I think that a clean way to fix this would be to conditionally define
these delete operators based on the C++ version.  So we would remove the
declarations, as you do in your commit, but place the definitions under
an "#if __cplusplus >= xyz".

Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 16:54   ` Simon Marchi
@ 2022-03-02 17:03     ` Pedro Alves
  2022-03-02 17:26       ` Simon Marchi
  2022-03-02 17:22     ` Andrew Burgess
  1 sibling, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2022-03-02 17:03 UTC (permalink / raw)
  To: Simon Marchi, Andrew Burgess, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner

On 2022-03-02 16:54, Simon Marchi via Gdb-patches wrote:

> The story of this is that ASan gave some alloc-dealloc mismatch warnings
> if we didn't define these specific delete operators, so we defined them
> in this commit:
> 
>   https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1
> 
> But for the variants of delete that are only introduced in C++14, it
> meant adding functions without an equivalent declaration when building
> in C++11, which produced some -Wmissing-declarations warnings.  So these
> declarations were added in this commit:
> 
>   https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdead1db23eddc4fd654305
> 
> The idea being that in C++11, these delete operators won't get used, but
> there will be a declaration to avoid the warning, and in C++14 the
> declarations will duplicate those found in headers, which is harmless.
> 
> And now here we are, we have a C++11 compiler that complains about
> declaring these delete operators.
> 
> So we can't simply remove the declarations and / or definitions, we
> would just re-introduce the problems fixed by these commits.
> 
> I think that a clean way to fix this would be to conditionally define
> these delete operators based on the C++ version.  So we would remove the
> declarations, as you do in your commit, but place the definitions under
> an "#if __cplusplus >= xyz".
> 

How can we be sure that some C++ library linked with gdb won't call them, though?
Like e.g., libsource-highlight.so.  It would seem to me that the best approach
would be to disable the warning around the declarations/definitions.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 16:54   ` Simon Marchi
  2022-03-02 17:03     ` Pedro Alves
@ 2022-03-02 17:22     ` Andrew Burgess
  2022-03-02 17:41       ` Simon Marchi
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Burgess @ 2022-03-02 17:22 UTC (permalink / raw)
  To: Simon Marchi, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner

Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 2022-03-02 11:30, Andrew Burgess wrote:
>> * 周春明(日月) via Gdb-patches <gdb-patches@sourceware.org> [2022-03-01 15:48:47 +0800]:
>> 
>>>
>>> Hi GDB maintainers,
>>>
>>> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
>>>
>>>  CXX new-op.o
>>> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>  extern void operator delete (void *p, std::size_t) noexcept;
>>>  ^
>>> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>  extern void operator delete[] (void *p, std::size_t) noexcept;
>>>  ^
>>> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>  operator delete (void *p, std::size_t) noexcept
>>>  ^
>>> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>  operator delete[] (void *p, std::size_t) noexcept
>> 
>> I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0.
>> I was unable to easily rebuild GCC 5.4.0 on my current development
>> machine to check if this is reproducible with upstream gcc, or is just
>> something impacting Ubuntu.  However, you can configure like:
>> 
>>   ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat"
>> 
>> to disable this warning/error which I believe should be fine.
>> 
>> For why this error is occurring, I'm honestly not 100% sure what the
>> error is telling us.  I _think_ what it's saying is that the delete
>> operator that we're declaring/defining conflicts with a "usual
>> deallocation function", which is added in c++14 and means something
>> specific.  I guess the idea is that maybe we're just randomly defining
>> this version of delete for some reason, and then, if/when we move on
>> to c++14 this function will get called unexpectedly by the language
>> runtime in some situations.
>> 
>> As time moved on I think this warning was relaxed, possibly with this
>> commit:
>> 
>>   https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html
>> 
>> All this makes me wonder if the usual deallocation functions are ever
>> actually used, and indeed, I applied the patch below, and GDB still
>> seems to build fine, so this might be an alternative approach.  Maybe
>> we should commit this to master?
>> 
>> Thanks,
>> Andrew
>> 
>> ---
>> 
>> diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
>> index 1d066ba..4faa557 100644
>> --- a/gdbsupport/new-op.cc
>> +++ b/gdbsupport/new-op.cc
>> @@ -27,11 +27,6 @@
>>  #include "host-defs.h"
>>  #include <new>
>>  
>> -/* These are declared in <new> starting C++14.  Add these here to enable
>> -   compilation using C++11. */
>> -extern void operator delete (void *p, std::size_t) noexcept;
>> -extern void operator delete[] (void *p, std::size_t) noexcept;
>
> The story of this is that ASan gave some alloc-dealloc mismatch warnings
> if we didn't define these specific delete operators, so we defined them
> in this commit:
>
>   https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1

I saw that commit, but it wasn't clear (to me) that _every_ supplied
delete was actually needed, or if the patch author just went wide.

The patch even says:

  There could be 16 operators delete but there are only 6, GDB uses 2 of
  them.  It depends on libraries and compiler which of the operators
  will get used.

But, that does seem to indicate that if I built with a different
compiler/c++-runtime, then I might end up using different delete
functions. 

>
> But for the variants of delete that are only introduced in C++14, it
> meant adding functions without an equivalent declaration when building
> in C++11, which produced some -Wmissing-declarations warnings.  So these
> declarations were added in this commit:
>
>   https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdead1db23eddc4fd654305

OK, so, I think you're saying that if we compile with C++14 then we
might need the delete functions I proposed deleting.

Just for my sanity, GDB currently targets C++11, right?  But, I guess
you're suggesting you'd like to keep these functions in place so we
_can_ compile with C++14 if we want?

>
> The idea being that in C++11, these delete operators won't get used, but
> there will be a declaration to avoid the warning, and in C++14 the
> declarations will duplicate those found in headers, which is harmless.
>
> And now here we are, we have a C++11 compiler that complains about
> declaring these delete operators.
>
> So we can't simply remove the declarations and / or definitions, we
> would just re-introduce the problems fixed by these commits.

I think this last statement depends on the "wanting to compile with
C++14" idea above, right? Otherwise...

>
> I think that a clean way to fix this would be to conditionally define
> these delete operators based on the C++ version.  So we would remove the
> declarations, as you do in your commit, but place the definitions under
> an "#if __cplusplus >= xyz".

... if we did this, and only ever compile with C++11, then this would be
equivalent to what I proposed, right?

I ask the above not (just) to be pedantic, but (mostly) to ensure I've
properly understood what's going on.

Below is a patch which maybe does what you suggest.  No commit message,
but if this is what you were thinking then I can write this up.

Thanks,
Andrew

---

diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
index 1d066ba..8699ec3 100644
--- a/gdbsupport/new-op.cc
+++ b/gdbsupport/new-op.cc
@@ -27,11 +27,6 @@
 #include "host-defs.h"
 #include <new>
 
-/* These are declared in <new> starting C++14.  Add these here to enable
-   compilation using C++11. */
-extern void operator delete (void *p, std::size_t) noexcept;
-extern void operator delete[] (void *p, std::size_t) noexcept;
-
 /* Override operator new / operator new[], in order to internal_error
    on allocation failure and thus query the user for abort/core
    dump/continue, just like xmalloc does.  We don't do this from a
@@ -116,19 +111,20 @@ operator delete (void *p, const std::nothrow_t&) noexcept
 }
 
 void
-operator delete (void *p, std::size_t) noexcept
+operator delete[] (void *p) noexcept
 {
-  return ::operator delete (p, std::nothrow);
+  return ::operator delete (p);
 }
 
 void
-operator delete[] (void *p) noexcept
+operator delete[] (void *p, const std::nothrow_t&) noexcept
 {
-  return ::operator delete (p);
+  return ::operator delete (p, std::nothrow);
 }
 
+#if __cplusplus >= 201402L
 void
-operator delete[] (void *p, const std::nothrow_t&) noexcept
+operator delete (void *p, std::size_t) noexcept
 {
   return ::operator delete (p, std::nothrow);
 }
@@ -138,5 +134,6 @@ operator delete[] (void *p, std::size_t) noexcept
 {
   return ::operator delete[] (p, std::nothrow);
 }
+#endif
 
 #endif


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 17:03     ` Pedro Alves
@ 2022-03-02 17:26       ` Simon Marchi
  2022-03-02 17:43         ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Marchi @ 2022-03-02 17:26 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner



On 2022-03-02 12:03, Pedro Alves wrote:
> How can we be sure that some C++ library linked with gdb won't call them, though?
> Like e.g., libsource-highlight.so.  It would seem to me that the best approach
> would be to disable the warning around the declarations/definitions.

For example, if GDB is built with C++11, but source-highlight is built with
C++14?

Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 17:22     ` Andrew Burgess
@ 2022-03-02 17:41       ` Simon Marchi
  2022-03-03 12:27         ` Andrew Burgess
  2022-03-03 14:18         ` Tom Tromey
  0 siblings, 2 replies; 13+ messages in thread
From: Simon Marchi @ 2022-03-02 17:41 UTC (permalink / raw)
  To: Andrew Burgess, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner



On 2022-03-02 12:22, Andrew Burgess wrote:
> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
>> On 2022-03-02 11:30, Andrew Burgess wrote:
>>> * 周春明(日月) via Gdb-patches <gdb-patches@sourceware.org> [2022-03-01 15:48:47 +0800]:
>>>
>>>>
>>>> Hi GDB maintainers,
>>>>
>>>> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
>>>>
>>>>  CXX new-op.o
>>>> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>  extern void operator delete (void *p, std::size_t) noexcept;
>>>>  ^
>>>> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>  extern void operator delete[] (void *p, std::size_t) noexcept;
>>>>  ^
>>>> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>  operator delete (void *p, std::size_t) noexcept
>>>>  ^
>>>> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>  operator delete[] (void *p, std::size_t) noexcept
>>>
>>> I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0.
>>> I was unable to easily rebuild GCC 5.4.0 on my current development
>>> machine to check if this is reproducible with upstream gcc, or is just
>>> something impacting Ubuntu.  However, you can configure like:
>>>
>>>   ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat"
>>>
>>> to disable this warning/error which I believe should be fine.
>>>
>>> For why this error is occurring, I'm honestly not 100% sure what the
>>> error is telling us.  I _think_ what it's saying is that the delete
>>> operator that we're declaring/defining conflicts with a "usual
>>> deallocation function", which is added in c++14 and means something
>>> specific.  I guess the idea is that maybe we're just randomly defining
>>> this version of delete for some reason, and then, if/when we move on
>>> to c++14 this function will get called unexpectedly by the language
>>> runtime in some situations.
>>>
>>> As time moved on I think this warning was relaxed, possibly with this
>>> commit:
>>>
>>>   https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html
>>>
>>> All this makes me wonder if the usual deallocation functions are ever
>>> actually used, and indeed, I applied the patch below, and GDB still
>>> seems to build fine, so this might be an alternative approach.  Maybe
>>> we should commit this to master?
>>>
>>> Thanks,
>>> Andrew
>>>
>>> ---
>>>
>>> diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
>>> index 1d066ba..4faa557 100644
>>> --- a/gdbsupport/new-op.cc
>>> +++ b/gdbsupport/new-op.cc
>>> @@ -27,11 +27,6 @@
>>>  #include "host-defs.h"
>>>  #include <new>
>>>  
>>> -/* These are declared in <new> starting C++14.  Add these here to enable
>>> -   compilation using C++11. */
>>> -extern void operator delete (void *p, std::size_t) noexcept;
>>> -extern void operator delete[] (void *p, std::size_t) noexcept;
>>
>> The story of this is that ASan gave some alloc-dealloc mismatch warnings
>> if we didn't define these specific delete operators, so we defined them
>> in this commit:
>>
>>   https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1
> 
> I saw that commit, but it wasn't clear (to me) that _every_ supplied
> delete was actually needed, or if the patch author just went wide.
> 
> The patch even says:
> 
>   There could be 16 operators delete but there are only 6, GDB uses 2 of
>   them.  It depends on libraries and compiler which of the operators
>   will get used.
> 
> But, that does seem to indicate that if I built with a different
> compiler/c++-runtime, then I might end up using different delete
> functions. 
> 
>>
>> But for the variants of delete that are only introduced in C++14, it
>> meant adding functions without an equivalent declaration when building
>> in C++11, which produced some -Wmissing-declarations warnings.  So these
>> declarations were added in this commit:
>>
>>   https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdead1db23eddc4fd654305
> 
> OK, so, I think you're saying that if we compile with C++14 then we
> might need the delete functions I proposed deleting.
> 
> Just for my sanity, GDB currently targets C++11, right?  But, I guess
> you're suggesting you'd like to keep these functions in place so we
> _can_ compile with C++14 if we want?

That was my idea, yes.  We require GDB to be buildable in C++11, but we
also regularly build it in C++14 and C++17 as well, since recent
compilers default to that version (and we don't force
-std=c++11/-std=gnu++11).

>> The idea being that in C++11, these delete operators won't get used, but
>> there will be a declaration to avoid the warning, and in C++14 the
>> declarations will duplicate those found in headers, which is harmless.
>>
>> And now here we are, we have a C++11 compiler that complains about
>> declaring these delete operators.
>>
>> So we can't simply remove the declarations and / or definitions, we
>> would just re-introduce the problems fixed by these commits.
> 
> I think this last statement depends on the "wanting to compile with
> C++14" idea above, right? Otherwise...

Yes.

>> I think that a clean way to fix this would be to conditionally define
>> these delete operators based on the C++ version.  So we would remove the
>> declarations, as you do in your commit, but place the definitions under
>> an "#if __cplusplus >= xyz".
> 
> ... if we did this, and only ever compile with C++11, then this would be
> equivalent to what I proposed, right?

Yes (but we currently don't restrict to C++11).

> I ask the above not (just) to be pedantic, but (mostly) to ensure I've
> properly understood what's going on.
> 
> Below is a patch which maybe does what you suggest.  No commit message,
> but if this is what you were thinking then I can write this up.

I think it is what I suggested, by per Pedro's message, that is probably
not good.  From what I understand, it is possible for a library GDB
links with to be built with a more recent C++, and call some "recent"
delete operator.  So even if we build GDB in C++11, we have to cover the
more recent delete operators introduced in C++14.

Simon

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 17:26       ` Simon Marchi
@ 2022-03-02 17:43         ` Pedro Alves
  0 siblings, 0 replies; 13+ messages in thread
From: Pedro Alves @ 2022-03-02 17:43 UTC (permalink / raw)
  To: Simon Marchi, Andrew Burgess, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner

On 2022-03-02 17:26, Simon Marchi wrote:
> 
> 
> On 2022-03-02 12:03, Pedro Alves wrote:
>> How can we be sure that some C++ library linked with gdb won't call them, though?
>> Like e.g., libsource-highlight.so.  It would seem to me that the best approach
>> would be to disable the warning around the declarations/definitions.
> 
> For example, if GDB is built with C++11, but source-highlight is built with
> C++14?

Yes.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 17:41       ` Simon Marchi
@ 2022-03-03 12:27         ` Andrew Burgess
  2022-03-03 14:18         ` Tom Tromey
  1 sibling, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2022-03-03 12:27 UTC (permalink / raw)
  To: Simon Marchi, 周春明(日月)
  Cc: Gdb-patches, Dominique Quatravaux, Louis-He, gdb-patches, Sam Warner

Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 2022-03-02 12:22, Andrew Burgess wrote:
>> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>> 
>>> On 2022-03-02 11:30, Andrew Burgess wrote:
>>>> * 周春明(日月) via Gdb-patches <gdb-patches@sourceware.org> [2022-03-01 15:48:47 +0800]:
>>>>
>>>>>
>>>>> Hi GDB maintainers,
>>>>>
>>>>> I tried to build new GDB12, but encounter below error, anyone could tell me how to fix it? Thanks!
>>>>>
>>>>>  CXX new-op.o
>>>>> ../../gdbsupport/new-op.cc:32:13: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>>  extern void operator delete (void *p, std::size_t) noexcept;
>>>>>  ^
>>>>> ../../gdbsupport/new-op.cc:33:13: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>>  extern void operator delete[] (void *p, std::size_t) noexcept;
>>>>>  ^
>>>>> ../../gdbsupport/new-op.cc:119:1: error: ‘void operator delete(void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>>  operator delete (void *p, std::size_t) noexcept
>>>>>  ^
>>>>> ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
>>>>>  operator delete[] (void *p, std::size_t) noexcept
>>>>
>>>> I was able to reproduce this on Ubuntu 16.04.1 with their gcc 5.4.0.
>>>> I was unable to easily rebuild GCC 5.4.0 on my current development
>>>> machine to check if this is reproducible with upstream gcc, or is just
>>>> something impacting Ubuntu.  However, you can configure like:
>>>>
>>>>   ../src/configure ...configure-flags-here... CXXFLAGS="-Wno-error=c++14-compat"
>>>>
>>>> to disable this warning/error which I believe should be fine.
>>>>
>>>> For why this error is occurring, I'm honestly not 100% sure what the
>>>> error is telling us.  I _think_ what it's saying is that the delete
>>>> operator that we're declaring/defining conflicts with a "usual
>>>> deallocation function", which is added in c++14 and means something
>>>> specific.  I guess the idea is that maybe we're just randomly defining
>>>> this version of delete for some reason, and then, if/when we move on
>>>> to c++14 this function will get called unexpectedly by the language
>>>> runtime in some situations.
>>>>
>>>> As time moved on I think this warning was relaxed, possibly with this
>>>> commit:
>>>>
>>>>   https://gcc.gnu.org/legacy-ml/gcc-patches/2015-05/msg01883.html
>>>>
>>>> All this makes me wonder if the usual deallocation functions are ever
>>>> actually used, and indeed, I applied the patch below, and GDB still
>>>> seems to build fine, so this might be an alternative approach.  Maybe
>>>> we should commit this to master?
>>>>
>>>> Thanks,
>>>> Andrew
>>>>
>>>> ---
>>>>
>>>> diff --git a/gdbsupport/new-op.cc b/gdbsupport/new-op.cc
>>>> index 1d066ba..4faa557 100644
>>>> --- a/gdbsupport/new-op.cc
>>>> +++ b/gdbsupport/new-op.cc
>>>> @@ -27,11 +27,6 @@
>>>>  #include "host-defs.h"
>>>>  #include <new>
>>>>  
>>>> -/* These are declared in <new> starting C++14.  Add these here to enable
>>>> -   compilation using C++11. */
>>>> -extern void operator delete (void *p, std::size_t) noexcept;
>>>> -extern void operator delete[] (void *p, std::size_t) noexcept;
>>>
>>> The story of this is that ASan gave some alloc-dealloc mismatch warnings
>>> if we didn't define these specific delete operators, so we defined them
>>> in this commit:
>>>
>>>   https://gitlab.com/gnutools/binutils-gdb/-/commit/5fff6115feae7aaa23c0ae8d144e1c8418ee2ee1
>> 
>> I saw that commit, but it wasn't clear (to me) that _every_ supplied
>> delete was actually needed, or if the patch author just went wide.
>> 
>> The patch even says:
>> 
>>   There could be 16 operators delete but there are only 6, GDB uses 2 of
>>   them.  It depends on libraries and compiler which of the operators
>>   will get used.
>> 
>> But, that does seem to indicate that if I built with a different
>> compiler/c++-runtime, then I might end up using different delete
>> functions. 
>> 
>>>
>>> But for the variants of delete that are only introduced in C++14, it
>>> meant adding functions without an equivalent declaration when building
>>> in C++11, which produced some -Wmissing-declarations warnings.  So these
>>> declarations were added in this commit:
>>>
>>>   https://gitlab.com/gnutools/binutils-gdb/-/commit/b038b53f1ff4bf00ecdead1db23eddc4fd654305
>> 
>> OK, so, I think you're saying that if we compile with C++14 then we
>> might need the delete functions I proposed deleting.
>> 
>> Just for my sanity, GDB currently targets C++11, right?  But, I guess
>> you're suggesting you'd like to keep these functions in place so we
>> _can_ compile with C++14 if we want?
>
> That was my idea, yes.  We require GDB to be buildable in C++11, but we
> also regularly build it in C++14 and C++17 as well, since recent
> compilers default to that version (and we don't force
> -std=c++11/-std=gnu++11).
>
>>> The idea being that in C++11, these delete operators won't get used, but
>>> there will be a declaration to avoid the warning, and in C++14 the
>>> declarations will duplicate those found in headers, which is harmless.
>>>
>>> And now here we are, we have a C++11 compiler that complains about
>>> declaring these delete operators.
>>>
>>> So we can't simply remove the declarations and / or definitions, we
>>> would just re-introduce the problems fixed by these commits.
>> 
>> I think this last statement depends on the "wanting to compile with
>> C++14" idea above, right? Otherwise...
>
> Yes.
>
>>> I think that a clean way to fix this would be to conditionally define
>>> these delete operators based on the C++ version.  So we would remove the
>>> declarations, as you do in your commit, but place the definitions under
>>> an "#if __cplusplus >= xyz".
>> 
>> ... if we did this, and only ever compile with C++11, then this would be
>> equivalent to what I proposed, right?
>
> Yes (but we currently don't restrict to C++11).
>
>> I ask the above not (just) to be pedantic, but (mostly) to ensure I've
>> properly understood what's going on.
>> 
>> Below is a patch which maybe does what you suggest.  No commit message,
>> but if this is what you were thinking then I can write this up.
>
> I think it is what I suggested, by per Pedro's message, that is probably
> not good.  From what I understand, it is possible for a library GDB
> links with to be built with a more recent C++, and call some "recent"
> delete operator.  So even if we build GDB in C++11, we have to cover the
> more recent delete operators introduced in C++14.

ACK.  Thanks for explaining though.  At least I feel I understand what's
going on now.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat]
  2022-03-02 17:41       ` Simon Marchi
  2022-03-03 12:27         ` Andrew Burgess
@ 2022-03-03 14:18         ` Tom Tromey
  1 sibling, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2022-03-03 14:18 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches
  Cc: Andrew Burgess, 周春明(日月),
	Simon Marchi, Gdb-patches, Dominique Quatravaux, Louis-He,
	Sam Warner

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

>> Just for my sanity, GDB currently targets C++11, right?  But, I guess
>> you're suggesting you'd like to keep these functions in place so we
>> _can_ compile with C++14 if we want?

Simon> That was my idea, yes.  We require GDB to be buildable in C++11, but we
Simon> also regularly build it in C++14 and C++17 as well, since recent
Simon> compilers default to that version (and we don't force
Simon> -std=c++11/-std=gnu++11).

We even have code that takes advantage of this, like gdb_string_view.h:

    #if __cplusplus >= 201703L

    #include <string_view>

Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-03-03 14:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  7:48 ../../gdbsupport/new-op.cc:137:1: error: ‘void operator delete [](void*, std::size_t)’ is a usual (non-placement) deallocation function in C++14 (or with -fsized-deallocation) [-Werror=c++14-compat] 周春明(日月)
2022-03-01 14:32 ` Simon Marchi
2022-03-02  3:08   ` 回复:../../gdbsupport/new-op.cc:137:1: " 周春明(日月)
2022-03-02 16:45     ` Simon Marchi
2022-03-02 16:30 ` ../../gdbsupport/new-op.cc:137:1: " Andrew Burgess
2022-03-02 16:54   ` Simon Marchi
2022-03-02 17:03     ` Pedro Alves
2022-03-02 17:26       ` Simon Marchi
2022-03-02 17:43         ` Pedro Alves
2022-03-02 17:22     ` Andrew Burgess
2022-03-02 17:41       ` Simon Marchi
2022-03-03 12:27         ` Andrew Burgess
2022-03-03 14:18         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).