This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 29632
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 4 Dec 2006 10:06:17 -0800
- Subject: C++ PATCH: PR 29632
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/29632, an accepts-invalid regression. When an
object "s" has a template conversion operator to pointer type, we want
to consider using it, for expressions like "p == s" -- but not when
"p" is NULL, since in that case we have no way to deduce the type of
the template parameter.
Tested on x86_64-unknown-linux-gnu, applied on the mainline.
I will apply this to 4.1/4.2 after testing completes.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
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 Mark Mitchell <mark@codesourcery.com>
PR c++/29632
* g++.dg/template/error23.C: New test.
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c (revision 119478)
+++ gcc/cp/call.c (working copy)
@@ -1811,14 +1811,19 @@ add_builtin_candidate (struct z_candidat
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;
Index: gcc/testsuite/g++.dg/template/error23.C
===================================================================
--- gcc/testsuite/g++.dg/template/error23.C (revision 0)
+++ gcc/testsuite/g++.dg/template/error23.C (revision 0)
@@ -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" }
+}
+
+