This is the mail archive of the gcc-bugs@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]

gcc-2.95.2: const members and no default ctor


------------------------- Problem -------------------------------------------
gcc-2.95.2 does not generate default constructor when class has const
member.
1. The const member has explicitly defined default ctor.
2. gcc seems willing to generate the default copy ctor.
------------------------- Example c++ file ----------------------------------
struct Fu
{
  int const kI ;

  Fu( void )
    : kI( 1 ) 
  { ; }

} ;

struct Bar
{
  Fu fFu ;
} ;

struct BarK
{
  Fu const kFu ;
} ;


int
main( void )
{
  Bar b0 ;
  BarK b1 ;

  return( b0.fFu.kI + b1.kFu.kI ) ;
}
------------------------- g++ -v output -----------------------------------
cd /home/page/junk/CC/
 g++ -v --save-temps gcc_const_member_no_default_ctor.C
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) gcc_const_member_no_default_ctor.C gcc_const_member_no_default_ctor.ii
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/../../../../sparc-sun-solaris2.7/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/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/sparc-sun-solaris2.7/2.95.2/cc1plus gcc_const_member_no_default_ctor.ii -quiet -dumpbase gcc_const_member_no_default_ctor.cc -version -o gcc_const_member_no_default_ctor.s
GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.7) compiled by GNU C version 2.95.2 19991024 (release).
gcc_const_member_no_default_ctor.C: In function `int main()':
gcc_const_member_no_default_ctor.C:26: no matching function for call to `BarK::BarK ()'
gcc_const_member_no_default_ctor.C:19: candidates are: BarK::BarK(const BarK &)

Compilation exited abnormally with code 1 at Wed Jan  5 11:21:34
------------------------------ .ii file -------------------------------------
# 1 "gcc_const_member_no_default_ctor.C"
struct Fu
{
  int const kI ;

  Fu( void )
    : kI( 1 ) 
  { ; }

} ;

struct Bar
{
  Fu fFu ;
} ;

struct BarK
{
  Fu const kFu ;
} ;


int
main( void )
{
  Bar b0 ;
  BarK b1 ;

  return( b0.fFu.kI + b1.kFu.kI ) ;
}

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