[gnu.g++.bug] g++ bugs

steveng@GARP.MIT.EDU (Stephen Ng) (04/11/89)

Hi, I've just tried porting over a large number of files from cfront to g++. 
I'm using g++ 1.34.0. Here are two of the problems I found:

1) Description:  g++ doesn't implicitly cast between fundamental types if the
return value of a member function is a reference which is immediately used as an
argument for another function.

Example:

char &ref_return();

class c
{
        public:
                int_arg(int i);
};

void foo()
{
        c c1;
        c1.int_arg(ref_return());
}
works in cfront, but produces "bad argument 0 for function 'c::int_arg (int)'
(type was char &)

Workaround:
Assign the return value to a temporary variable and use the temporary as the
function argument.

2) Description:  g++ doesn't initialize by assignment for a class if the class
a) has no constructor explicitly declared and b) if the class has a member class
 which has a constructor.

Example:
                
class Member {
public:
        Member();
};

class Foo {
        Member mem;
};

void func()
{
        Foo f1;
        Foo f2 = f1;
}

This passes through cfront properly, but generates a "unexpected argument to
constructor 'Foo'" error in g++.
Workaround: 
        explicitly declare a constructor for class Foo.

Thanks,

Steve

donn@CS.UTAH.EDU (Donn Seeley) (07/25/89)

	typedef int (*PF)();
	class foo_c { PF fp; public: void m(); };
	void foo_c::m() { return fp(); }

G++ 1.35.0 produces the error message 'component `fp' is not a method'.

There appears to be a logic error in the function hack_identifier in
cplus-method.c, which persists in G++ 1.35.1 (which we aren't running
since we're waiting for 1.36.0).  The special case of a data member
that is a pointer to a function or to a member function is incorrectly
recognized; here's the fix I made:

*** /tmp/,RCSt1009094	Mon Jul 24 18:17:24 1989
--- cplus-method.c	Mon Jul 24 17:50:04 1989
***************
*** 2171,2178 ****
  		&& TREE_CODE (type) != FUNCTION_TYPE
  		&& TREE_CODE (type) != METHOD_TYPE
  		&& (TREE_CODE (type) != POINTER_TYPE
! 		    || TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
! 		    || TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE))
  	    {
  	      error ("component `%s' is not a method",
  		     IDENTIFIER_POINTER (name));
--- 2171,2178 ----
  		&& TREE_CODE (type) != FUNCTION_TYPE
  		&& TREE_CODE (type) != METHOD_TYPE
  		&& (TREE_CODE (type) != POINTER_TYPE
! 		    || (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
! 			&& TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)))
  	    {
  	      error ("component `%s' is not a method",
  		     IDENTIFIER_POINTER (name));

Donn Seeley    University of Utah CS Dept    donn@cs.utah.edu
40 46' 6"N 111 50' 34"W    (801) 581-5668    utah-cs!donn