re PR c++/8214 (character conversion problem)
authorMark Mitchell <mark@codesourcery.com>
Sun, 1 Dec 2002 02:11:05 +0000 (02:11 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Dec 2002 02:11:05 +0000 (02:11 +0000)
PR c++/8214
* g++.dg/init/string1.C: New test.

PR c++/8214
* typeck.c (convert_for_assignment): Do not use
decl_constant_value on the operand.

From-SVN: r59668

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/string1.C [new file with mode: 0644]

index 3a586ae..87cfabe 100644 (file)
@@ -1,5 +1,11 @@
 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.
+
+2002-11-30  Mark Mitchell  <mark@codesourcery.com>
+
        PR c++/8511
        * pt.c (instantiate_decl): Handle template friends defined outside
        of the class correctly.
index 1366ea0..6a0ec18 100644 (file)
@@ -5859,8 +5859,16 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
   /* 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);
+  
+  /* 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 48658bf..1ac64f5 100644 (file)
@@ -1,5 +1,10 @@
 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++/8511
        * g++.dg/template/friend8.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/init/string1.C b/gcc/testsuite/g++.dg/init/string1.C
new file mode 100644 (file)
index 0000000..597b861
--- /dev/null
@@ -0,0 +1,8 @@
+extern void f (char*);
+
+extern const char * const target = "foo";
+
+void g ()
+{
+  f (target); // { dg-error "conversion" }
+}