This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Fix bug 3624
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH]: Fix bug 3624
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Wed, 25 Jul 2001 20:38:24 +0100
- CC: mark at codesourcery dot com
- Organization: Codesourcery LLC
Mark,
Template instantiation can leave expressions with REFERENCE_TYPE,
which we were not calling convert_from_reference on. I recall fixing
this before, but clearly missed the method call case. This moves
the conversions earlier in build_new_op, and does the right thing
for argument lists too.
booted & tested on i686-pc-linux-gnu, ok for branch & mainline?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-07-25 Nathan Sidwell <nathan@codesourcery.com>
PR c++/3624
* call.c (resolve_args): Simplify, call
convert_from_reference.
(build_new_op): Resolve and convert from reference ARG1
earlier. Adjust ARG2 & ARG3 resolve and conversion.
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.276
diff -c -3 -p -r1.276 call.c
*** call.c 2001/07/25 09:38:25 1.276
--- call.c 2001/07/25 12:51:39
*************** resolve_args (args)
*** 2556,2570 ****
tree t;
for (t = args; t; t = TREE_CHAIN (t))
{
! if (TREE_VALUE (t) == error_mark_node)
return error_mark_node;
! else if (TREE_CODE (TREE_TYPE (TREE_VALUE (t))) == VOID_TYPE)
{
error ("invalid use of void expression");
return error_mark_node;
}
! else if (TREE_CODE (TREE_VALUE (t)) == OFFSET_REF)
! TREE_VALUE (t) = resolve_offset_ref (TREE_VALUE (t));
}
return args;
}
--- 2556,2574 ----
tree t;
for (t = args; t; t = TREE_CHAIN (t))
{
! tree arg = TREE_VALUE (t);
!
! if (arg == error_mark_node)
return error_mark_node;
! else if (VOID_TYPE_P (TREE_TYPE (arg)))
{
error ("invalid use of void expression");
return error_mark_node;
}
! else if (TREE_CODE (arg) == OFFSET_REF)
! arg = resolve_offset_ref (arg);
! arg = convert_from_reference (arg);
! TREE_VALUE (t) = arg;
}
return args;
}
*************** build_new_op (code, flags, arg1, arg2, a
*** 3220,3225 ****
--- 3224,3233 ----
else
fnname = ansi_opname (code);
+ if (TREE_CODE (arg1) == OFFSET_REF)
+ arg1 = resolve_offset_ref (arg1);
+ arg1 = convert_from_reference (arg1);
+
switch (code)
{
case NEW_EXPR:
*************** build_new_op (code, flags, arg1, arg2, a
*** 3236,3254 ****
break;
}
- /* The comma operator can have void args. */
- if (TREE_CODE (arg1) == OFFSET_REF)
- arg1 = resolve_offset_ref (arg1);
- if (arg2 && TREE_CODE (arg2) == OFFSET_REF)
- arg2 = resolve_offset_ref (arg2);
- if (arg3 && TREE_CODE (arg3) == OFFSET_REF)
- arg3 = resolve_offset_ref (arg3);
-
- arg1 = convert_from_reference (arg1);
if (arg2)
! arg2 = convert_from_reference (arg2);
if (arg3)
! arg3 = convert_from_reference (arg3);
if (code == COND_EXPR)
{
--- 3244,3261 ----
break;
}
if (arg2)
! {
! if (TREE_CODE (arg2) == OFFSET_REF)
! arg2 = resolve_offset_ref (arg2);
! arg2 = convert_from_reference (arg2);
! }
if (arg3)
! {
! if (TREE_CODE (arg3) == OFFSET_REF)
! arg3 = resolve_offset_ref (arg3);
! arg3 = convert_from_reference (arg3);
! }
if (code == COND_EXPR)
{
// Build don't link:
//
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 25 Jul 2001 <nathan@codesourcery.com>
// Origin: gustavo@geneura.ugr.es
// Bug 3624. Template instantiation of a reference type was not
// converted from reference when doing a call.
#include <iostream>
using namespace std;
template <class A, class B, class C, C& c, bool d> class eo: public A
{
public:
eo()
{
cout << this->x << " " << this->y << " "
<< c(*this) << " "
<< ((d)?"true":"false") << endl;
}
private:
B b;
};
struct XY
{
float x, y;
XY(): x(1), y(0.1) {}
};
float fitness(const XY& a)
{
return a.x + a.y;
}
struct fitness2
{
float operator()(const XY& a)
{
return a.x - a.y;
}
float f(const XY& a)
{
return a.x - a.y;
}
};
struct fitness3
{
float operator()(const XY& a)
{
return a.x / a.y;
}
};
fitness2 f2;
fitness3 f3;
int main()
{
eo<XY, float, fitness2, f2, true> eo2;
eo<XY, float, fitness3, f3, true> eo3;
return 0;
}