public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Ben Dorman <dorman@pcp259033pcs.howard01.md.comcast.net>
To: gcc-gnats@gcc.gnu.org
Subject: c++/6426: gcc produces incorrect call to compiler generated copy ctor
Date: Tue, 23 Apr 2002 08:56:00 -0000	[thread overview]
Message-ID: <200204231549.g3NFnp512707@pcp259033pcs.howard01.md.comcast.net> (raw)


>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:


             reply	other threads:[~2002-04-23 15:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23  8:56 Ben Dorman [this message]
2002-04-23 18:15 rodrigc
2002-04-24  9:36 rodrigc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200204231549.g3NFnp512707@pcp259033pcs.howard01.md.comcast.net \
    --to=dorman@pcp259033pcs.howard01.md.comcast.net \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).