This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 8214
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 30 Nov 2002 18:05:04 -0800
- Subject: C++ PATCH: PR 8214
- Reply-to: mark at codesourcery dot com
This patch fixes PR 8214; the comment in the code pretty much says it
all.
Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-11-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8214
* g++.dg/init/string1.C: New test.
2002-11-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8214
* typeck.c (convert_for_assignment): Do not use
decl_constant_value on the operand.
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.434
diff -c -p -r1.434 typeck.c
*** cp/typeck.c 26 Nov 2002 17:40:56 -0000 1.434
--- cp/typeck.c 1 Dec 2002 02:07:05 -0000
*************** convert_for_assignment (type, rhs, errty
*** 5859,5866 ****
/* Simplify the RHS if possible. */
if (TREE_CODE (rhs) == CONST_DECL)
rhs = DECL_INITIAL (rhs);
! else if (coder != ARRAY_TYPE)
! rhs = decl_constant_value (rhs);
/* [expr.ass]
--- 5859,5874 ----
/* Simplify the RHS if possible. */
if (TREE_CODE (rhs) == CONST_DECL)
rhs = DECL_INITIAL (rhs);
!
! /* We do not use decl_constant_value here because of this case:
!
! const char* const s = "s";
!
! The conversion rules for a string literal are more lax than for a
! variable; in particular, a string literal can be converted to a
! "char *" but the variable "s" cannot be converted in the same
! way. If the conversion is allowed, the optimization should be
! performed while creating the converted expression. */
/* [expr.ass]
Index: testsuite/g++.dg/init/string1.C
===================================================================
RCS file: testsuite/g++.dg/init/string1.C
diff -N testsuite/g++.dg/init/string1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/string1.C 1 Dec 2002 02:07:08 -0000
***************
*** 0 ****
--- 1,8 ----
+ extern void f (char*);
+
+ extern const char * const target = "foo";
+
+ void g ()
+ {
+ f (target); // { dg-error "conversion" }
+ }