This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/6426: gcc produces incorrect call to compiler generated copy ctor
- From: Ben Dorman <dorman at pcp259033pcs dot howard01 dot md dot comcast dot net>
- To: gcc-gnats at gcc dot gnu dot org
- Date: Tue, 23 Apr 2002 11:49:51 -0400
- Subject: c++/6426: gcc produces incorrect call to compiler generated copy ctor
>Number: 6426
>Category: c++
>Synopsis: gcc produces incorrect call to compiler generated copy ctor
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Apr 23 08:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Ben Dorman
>Release: 3.0.3
>Organization:
>Environment:
System: Linux pcp259033pcs.howard01.md.comcast.net 2.4.2-2 #1 Sun Apr 8 19:37:14 EDT 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.0.3/configure --enable-threads --prefix=/usr
>Description:
g++ incorrectly generates call to compiler-generated copy ctor for exception
>How-To-Repeat:
consider following function:
void FITS::open (RWmode mode)
{
//## begin CCfits::FITS::open%380B3C3FACA8.body preserve=yes
// C code generates integer status flag
int status = fits_open_file(&m_FITSImpl->fptr(), m_FITSImpl->name().c_str(), mode, &status);
const std::string diag (m_FITSImpl->name());
bool silent = s_verboseMode;
if (status != 0)
{
if (status == FILE_NOT_OPENED) throw CantOpen(diag,silent);
else throw FitsError(status);
}
//## end CCfits::FITS::open%380B3C3FACA8.body
}
FITS::CantOpen is an exception class defined as follows:
class CantOpen : public FitsException //## Inherits: <unnamed>%39C8EB1D02C0
{
public:
//## Constructors (specified)
//## Operation: CantOpen%39C8E9FA01BA
CantOpen (const string& diag, bool silent = false);
explicit CantOpen(const CantOpen&);
protected:
private:
private: //## implementation
};
[note: the explicit copy ctor is not usually present in these declarations but is added
here to demonstrate the problem]
Compilation of the above file with the explicit keyword generates following output:-
c++ -DHAVE_CONFIG_H -I. -I. -I. -I./.. -I/home/dorman/cpp/include -g -v -save-temps -Wall -c FITS.cxx
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/specs
Configured with: ../gcc-3.0.3/configure --enable-threads --prefix=/usr
Thread model: posix
gcc version 3.0.3
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/cpp0 -lang-c++ -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -I. -I. -I. -I./.. -I/home/dorman/cpp/include -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=3 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Wall -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ -DHAVE_CONFIG_H FITS.cxx FITS.ii
GNU CPP version 3.0.3 (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i686-pc-linux-gnu/include"
ignoring duplicate directory "."
ignoring duplicate directory "."
#include "..." search starts here:
#include <...> search starts here:
.
..
/home/dorman/cpp/include
/usr/include/g++-v3
/usr/include/g++-v3/i686-pc-linux-gnu
/usr/include/g++-v3/backward
/usr/local/include
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0.3/cc1plus -fpreprocessed FITS.ii -quiet -dumpbase FITS.cxx -g -Wall -version -o FITS.s
GNU CPP version 3.0.3 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.3 (i686-pc-linux-gnu)
compiled by GNU C version 3.0.3.
FITS.cxx: In member function `void CCfits::FITS::open(CCfits::RWmode)':
FITS.cxx:544: no matching function for call to
`CCfits::FITS::CantOpen::CantOpen(CCfits::FITS::CantOpen)'
FITS.cxx:104: candidates are: CCfits::FITS::CantOpen::CantOpen(const
std::string&, bool = false)
make: *** [FITS.o] Error 1
showing that the compiler wants to call the copy ctor, not the custom ctor despite a perfect
match to argts.
>Fix:
Removing the 'explicit' keyword allows code to compile but exception handling
may result in terminate() call instead of safe behaviour.
>Release-Note:
>Audit-Trail:
>Unformatted: