2.95: nested constructors seem to cause unwarranted error in this situation.

Christopher Baus christopher@baus.net
Thu Aug 5 02:41:00 GMT 1999


I believe I have found an undocumented C++ bug that occurs under fairly
specific
conditions.

It seems calling a triply nested constructor causes an error if there
are two or more parameters passed to the outside constructor.  I have
tried to reduce the sample code as simple as possible.

I believe the test example is 100% acceptable, and (I hate to say it),
but the MS compiler seems to accept this code.

Thanks for the good work.  Requested output follows.

./~christopher

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
http://www.baus.net/

"I was stirring my brandy with a nail, boys" -- Tom Waits
===================================================

[root@nomad src]# g++ -v --save-temps test.cpp
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/cpp -lang-c++ -v -D__GNUC__=2 
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -
Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asyst
em(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i38
6__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
test.cpp test.ii
GNU CPP version 2.95 19990728 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../include/g++-3
 /usr/local/include

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../i686-pc-linux-gnu/
include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/cc1plus
test.ii -quiet -dumpbase test.cc -version -o test.s
GNU C++ version 2.95 19990728 (release) (i686-pc-linux-gnu) compiled by GNU
C version 2.95 19990728 (release).
test.cpp: In function `int main()':
test.cpp:28: redeclaration of `class B A'
test.cpp:28: `class B A' previously declared here
[root@nomad downloads]# cat out
[root@nomad downloads]# g++ -v --save-temps test.cpp $3>out
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/cpp -lang-c++ -v -D__GNUC__=2 
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -
Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asyst
em(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i38
6__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__
test.cpp test.ii
GNU CPP version 2.95 19990728 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../include/g++-3
 /usr/local/include

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../i686-pc-linux-gnu/
include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/cc1plus
test.ii -quiet -dumpbase test.cc -version -o test.s
GNU C++ version 2.95 19990728 (release) (i686-pc-linux-gnu) compiled by GNU
C version 2.95 19990728 (release).
test.cpp: In function `int main()':
test.cpp:28: redeclaration of `class B A'
test.cpp:28: `class B A' previously declared here

===========================================
# 1 "test.cpp"
class A
{
public:
  A(int i);

};



class B
{
public:
  B(A a)
    {}

};

class C
{
public:
  C(B b, B b1)
    {}
};


int main()
{
  C c( B(A(1)), B(A(2)) );

  return 0;
}





More information about the Gcc-bugs mailing list