From 98a8649c705c0fd8c7d8453f0ce2ce17596f05a7 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 13 Dec 2018 12:24:16 -0500
Subject: [PATCH 13/21] FIXME: partial fix for PR c++/71302

---
 gcc/cp/call.c                                      |  4 +--
 .../g++.dg/warn/Wzero-as-null-pointer-constant-1.C | 36 +++++++++++-----------
 .../g++.dg/warn/Wzero-as-null-pointer-constant-5.C |  2 +-
 .../g++.dg/warn/Wzero-as-null-pointer-constant-7.C |  4 +--
 .../g++.dg/warn/Wzero-as-null-pointer-constant-8.C | 16 ++++++++++
 5 files changed, 39 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-8.C

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index e2f8fe1..91645db 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -6731,8 +6731,8 @@ conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
   else if (null_ptr_cst_p (expr) &&
 	   (TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype)))
     {
-      location_t loc =
-       expansion_point_location_if_in_system_header (input_location);
+      location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
+      loc = expansion_point_location_if_in_system_header (loc);
       maybe_warn_zero_as_null_pointer_constant (expr, loc);
     }
 }
diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-1.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-1.C
index d0f62b2..5047a61 100644
--- a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-1.C
+++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-1.C
@@ -13,18 +13,18 @@ int*        ps;
 
 void f()
 {
-  pointmemfun pmf(0);   // { dg-warning "zero as null pointer" }
-  pointdmem   pdm(0);   // { dg-warning "zero as null pointer" }
-  pointfun    pf(0);    // { dg-warning "zero as null pointer" }
-  int*        p(0);     // { dg-warning "zero as null pointer" }
+  pointmemfun pmf(0);   // { dg-warning "19: zero as null pointer" }
+  pointdmem   pdm(0);   // { dg-warning "19: zero as null pointer" }
+  pointfun    pf(0);    // { dg-warning "18: zero as null pointer" }
+  int*        p(0);     // { dg-warning "17: zero as null pointer" }
 
-  pmf = 0;              // { dg-warning "zero as null pointer" }
+  pmf = 0;              // { dg-warning "9: zero as null pointer" }
 
-  pdm = 0;              // { dg-warning "zero as null pointer" }
+  pdm = 0;              // { dg-warning "9: zero as null pointer" }
 
-  pf = 0;               // { dg-warning "zero as null pointer" }
+  pf = 0;               // { dg-warning "8: zero as null pointer" }
 
-  p = 0;                // { dg-warning "zero as null pointer" }
+  p = 0;                // { dg-warning "7: zero as null pointer" }
 
   if (pmf)
     ;
@@ -50,22 +50,22 @@ void f()
   if (!p)
     ;
 
-  if (pmf == 0)         // { dg-warning "zero as null pointer" }
+  if (pmf == 0)         // { dg-warning "14: zero as null pointer" }
     ;
   
-  if (pdm == 0)         // { dg-warning "zero as null pointer" }
+  if (pdm == 0)         // { dg-warning "14: zero as null pointer" }
     ;
 
-  if (pf == 0)          // { dg-warning "zero as null pointer" }
+  if (pf == 0)          // { dg-warning "13: zero as null pointer" }
     ;
 
-  if (p == 0)           // { dg-warning "zero as null pointer" }
+  if (p == 0)           // { dg-warning "12: zero as null pointer" }
     ;
 
-  if (0 == pmf)         // { dg-warning "zero as null pointer" }
+  if (0 == pmf)         // { dg-warning "12: zero as null pointer" }
     ;
   
-  if (0 == pdm)         // { dg-warning "zero as null pointer" }
+  if (0 == pdm)         // { dg-warning "12: zero as null pointer" }
     ;
 
   if (0 == pf)          // { dg-warning "zero as null pointer" }
@@ -74,16 +74,16 @@ void f()
   if (0 == p)           // { dg-warning "zero as null pointer" }
     ;
 
-  if (pmf != 0)         // { dg-warning "zero as null pointer" }
+  if (pmf != 0)         // { dg-warning "14: zero as null pointer" }
     ;
   
-  if (pdm != 0)         // { dg-warning "zero as null pointer" }
+  if (pdm != 0)         // { dg-warning "14: zero as null pointer" }
     ;
 
-  if (pf != 0)          // { dg-warning "zero as null pointer" }
+  if (pf != 0)          // { dg-warning "13: zero as null pointer" }
     ;
 
-  if (p != 0)           // { dg-warning "zero as null pointer" }
+  if (p != 0)           // { dg-warning "12: zero as null pointer" }
     ;
 
   if (0 != pmf)         // { dg-warning "zero as null pointer" }
diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
index 4269bed..01662f5 100644
--- a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
+++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-5.C
@@ -3,7 +3,7 @@
 
 struct foo
 {
-  foo(void* a = 0) {};      // { dg-warning "zero as null pointer" }
+  foo(void* a = 0) {};      // { dg-warning "17: zero as null pointer" }
 };
 
 void* fun(void* a = 0) {};  // { dg-warning "zero as null pointer" }
diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C
index 0d06dbf..571a4cf 100644
--- a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C
+++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C
@@ -8,6 +8,6 @@ void test01()
   char* x(NULL);
   char* x2{NULL};
   char* x3 = NULL;
-  char* x4(0); // { dg-warning "zero as null pointer" }
-  char* x5 = 0; // { dg-warning "zero as null pointer" }
+  char* x4(0); // { dg-warning "12: zero as null pointer" }
+  char* x5 = 0; // { dg-warning "14: zero as null pointer" }
 }
diff --git a/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-8.C b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-8.C
new file mode 100644
index 0000000..03124fa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-8.C
@@ -0,0 +1,16 @@
+// PR c++/71302
+// { dg-do compile }
+// { dg-options "-Wzero-as-null-pointer-constant" }
+
+#include <cstddef>
+
+void Function1(const char* Param);
+void Function2(const char* Param1, int Param2);
+
+void test ()
+{
+  Function1(0);  // { dg-warning "13: zero as null pointer" }
+  Function1(NULL);
+  Function2(0, 0); // { dg-warning "13: zero as null pointer" }
+  Function2(NULL, 0);
+}
-- 
1.8.5.3

