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

Patrick Palka patrick@parcs.ath.cx
Thu Dec 10 23:55:00 GMT 2015


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

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



More information about the Gcc-patches mailing list