diff mbox

Fix PR c++/68831 (superfluous -Waddress warning for C++ delete)

Message ID 1449791666-13298-1-git-send-email-patrick@parcs.ath.cx
State New
Headers show

Commit Message

Patrick Palka Dec. 10, 2015, 11:54 p.m. UTC
Is this OK to commit if bootstrap + regtest on x86_64 succeeds?

gcc/cp/ChangeLog:

	PR c++/68831
	* init.c (build_delete): Use a warning sentinel to disable
	-Waddress warnings when building the conditional that tests
	if the operand is NULL.

gcc/testsuite/ChangeLog:

	PR c++/68831
	* g++.dg/pr68831.C: New test.
---
 gcc/cp/init.c                  |  1 +
 gcc/testsuite/g++.dg/pr68831.C | 10 ++++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/pr68831.C

Comments

Patrick Palka Dec. 17, 2015, 5:47 p.m. UTC | #1
On Thu, Dec 10, 2015 at 6:54 PM, Patrick Palka <patrick@parcs.ath.cx> wrote:
> Is this OK to commit if bootstrap + regtest on x86_64 succeeds?
>
> gcc/cp/ChangeLog:
>
>         PR c++/68831
>         * init.c (build_delete): Use a warning sentinel to disable
>         -Waddress warnings when building the conditional that tests
>         if the operand is NULL.
>
> gcc/testsuite/ChangeLog:
>
>         PR c++/68831
>         * g++.dg/pr68831.C: New test.

Ping.

> ---
>  gcc/cp/init.c                  |  1 +
>  gcc/testsuite/g++.dg/pr68831.C | 10 ++++++++++
>  2 files changed, 11 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr68831.C
>
> diff --git a/gcc/cp/init.c b/gcc/cp/init.c
> index 5ecf9fb..2fffc61 100644
> --- a/gcc/cp/init.c
> +++ b/gcc/cp/init.c
> @@ -4439,6 +4439,7 @@ build_delete (tree otype, tree addr, special_function_kind auto_delete,
>        else
>         {
>           /* Handle deleting a null pointer.  */
> +         warning_sentinel s (warn_address);
>           ifexp = fold (cp_build_binary_op (input_location,
>                                             NE_EXPR, addr, nullptr_node,
>                                             complain));
> diff --git a/gcc/testsuite/g++.dg/pr68831.C b/gcc/testsuite/g++.dg/pr68831.C
> new file mode 100644
> index 0000000..8d32819
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr68831.C
> @@ -0,0 +1,10 @@
> +// PR c++/68831
> +// { dg-options "-Waddress" }
> +
> +class DenseMap {
> +public:
> +  ~DenseMap();
> +};
> +extern const DenseMap &GCMap;
> +void foo() { delete &GCMap; }
> +
> --
> 2.6.4.491.gda30757.dirty
>
Jason Merrill Dec. 17, 2015, 7:34 p.m. UTC | #2
OK.

Jason
diff mbox

Patch

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 5ecf9fb..2fffc61 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -4439,6 +4439,7 @@  build_delete (tree otype, tree addr, special_function_kind auto_delete,
       else
 	{
 	  /* Handle deleting a null pointer.  */
+	  warning_sentinel s (warn_address);
 	  ifexp = fold (cp_build_binary_op (input_location,
 					    NE_EXPR, addr, nullptr_node,
 					    complain));
diff --git a/gcc/testsuite/g++.dg/pr68831.C b/gcc/testsuite/g++.dg/pr68831.C
new file mode 100644
index 0000000..8d32819
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr68831.C
@@ -0,0 +1,10 @@ 
+// PR c++/68831
+// { dg-options "-Waddress" }
+
+class DenseMap {
+public:
+  ~DenseMap();
+};
+extern const DenseMap &GCMap;
+void foo() { delete &GCMap; }
+