From d3d4beab4467b0c73d70d537f5449753555422f2 Mon Sep 17 00:00:00 2001
From: mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 4 Dec 2006 18:00:32 +0000
Subject: [PATCH] 	PR c++/29632 	* call.c (add_builtin_candidate): Do
 not permit NULL pointer 	constants to be compared with template
 parameters. 	PR c++/29632 	* g++.dg/template/error23.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119499 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog                        |  6 ++++++
 gcc/cp/call.c                           | 11 ++++++++---
 gcc/testsuite/ChangeLog                 |  5 +++++
 gcc/testsuite/g++.dg/template/error23.C | 17 +++++++++++++++++
 4 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/error23.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index cf577f0d9f84..a4c1a1132627 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2006-12-04  Mark Mitchell  <mark@codesourcery.com>
+
+	PR c++/29632
+	* call.c (add_builtin_candidate): Do not permit NULL pointer
+	constants to be compared with template parameters.
+
 2006-12-04  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* pt.c (for_each_template_parm_r) <INTEGER_TYPE>: New case.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index cfb566b16b0f..34187039243a 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1811,14 +1811,19 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code,
 	break;
       if (TYPE_PTR_P (type1) && TYPE_PTR_P (type2))
 	break;
-      if (TREE_CODE (type1) == ENUMERAL_TYPE && TREE_CODE (type2) == ENUMERAL_TYPE)
+      if (TREE_CODE (type1) == ENUMERAL_TYPE 
+	  && TREE_CODE (type2) == ENUMERAL_TYPE)
 	break;
-      if (TYPE_PTR_P (type1) && null_ptr_cst_p (args[1]))
+      if (TYPE_PTR_P (type1) 
+	  && null_ptr_cst_p (args[1])
+	  && !uses_template_parms (type1))
 	{
 	  type2 = type1;
 	  break;
 	}
-      if (null_ptr_cst_p (args[0]) && TYPE_PTR_P (type2))
+      if (null_ptr_cst_p (args[0]) 
+	  && TYPE_PTR_P (type2)
+	  && !uses_template_parms (type2))
 	{
 	  type1 = type2;
 	  break;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e50bc592d5f1..3e0e6412e4ff 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-12-04  Mark Mitchell  <mark@codesourcery.com>
+
+	PR c++/29632
+	* g++.dg/template/error23.C: New test.
+
 2006-12-04  Uros Bizjak  <ubizjak@gmail.com>
 
 	* gcc.target/i386/sse-18.c: Pass if CPU has no SSE2 support.
diff --git a/gcc/testsuite/g++.dg/template/error23.C b/gcc/testsuite/g++.dg/template/error23.C
new file mode 100644
index 000000000000..8e5dee76dda3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/error23.C
@@ -0,0 +1,17 @@
+// PR c++/29632
+
+struct nullptr_type {
+
+  nullptr_type ( void ) {}
+
+  template < typename T >
+  operator T* ( void ) const {
+    return ( 0 );
+  }
+} const nullptr;
+
+int main ( void ) {
+  0 == nullptr; // { dg-error "match" }
+}
+
+
-- 
GitLab