This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[C++ PATCH] Fix g++.other/init16.C


Hi!

The following patch modifies init16.C test so that it does not need <string>
(otherwise it would had to s/string x/std::string x/ and it is always better
not to include anything in the tests) plus an attempt to fix it (fixes the
testcase and does not create any regressions, though I'm not 100% sure if it
shouldn't be elsewhere). I think the test got broken in Mark's 1999-07-23
reference binding change (previously convert_like simply called there
convert_to_reference instead of all the code there and convert_to_reference
handled that gracefully).
Ok to commit? If not, is it ok to commit at least the test change?

2001-02-16  Jakub Jelinek  <jakub@redhat.com>

	* call.c (convert_like_real): Create a temporary for non-constant
	constructor.

	* g++.old-deja/g++.other/init16.C: Update the test so that it does
	not need <string> and also tests the initialization at runtime.

--- gcc/cp/call.c.jj	Thu Feb 15 14:15:02 2001
+++ gcc/cp/call.c	Fri Feb 16 17:29:08 2001
@@ -3850,7 +3850,9 @@ convert_like_real (convs, expr, fn, argn
 	tree ref_type = totype;
 
 	/* If necessary, create a temporary.  */
-	if (NEED_TEMPORARY_P (convs))
+	if (NEED_TEMPORARY_P (convs)
+	    || (TREE_CODE (expr) == CONSTRUCTOR
+		&& !TREE_CONSTANT (expr)))
 	  {
 	    tree type = TREE_TYPE (TREE_OPERAND (convs, 0));
 	    expr = build_target_expr_with_type (expr, type);
--- gcc/testsuite/g++.old-deja/g++.other/init16.C.jj	Wed Nov  8 14:22:06 2000
+++ gcc/testsuite/g++.old-deja/g++.other/init16.C	Fri Feb 16 17:41:28 2001
@@ -1,11 +1,28 @@
-// Build don't link:
 // Origin: Jakub Jelinek <jakub@redhat.com>
 
-// excess errors test - XFAIL *-*-*
-
-#include <string>
+struct bar {
+  char c;
+  bar (const char *);
+  bar (const bar &);
+};
 
 struct foo {
-  string x;
+  bar x;
 };
+
 extern const struct foo y = { "foo" };
+
+bar::bar (const bar &ref)
+{
+  c = ref.c;
+}
+
+bar::bar (const char *p)
+{
+  c = p[2];
+}
+
+int main ()
+{
+  return y.x.c != 'o';
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]