https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71765

            Bug ID: 71765
           Summary: incorrectly accepts invalid C++ code that invokes base
                    class constructor
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

Please see: 

https://llvm.org/bugs/show_bug.cgi?id=28408

in particular, Richard Smith's comment. 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160704 (experimental) [trunk revision 237986] (GCC) 
$ 
$ g++-trunk -c -Wall -Wextra -pedantic -std=c++98 good.cpp
$ 
$ clang++-3.8 -c good.cpp
good.cpp:14:7: error: destructor type 'A' in object destruction expression does
not match the type 'B' of the
      object being destroyed
  b->~A (); 
      ^
good.cpp:1:8: note: type 'A' is declared here
struct A 
       ^
1 error generated.
$ 
$ cat good.cpp
struct A 
{
  virtual ~A () {}
};

struct B : public A 
{
  virtual ~B () {} 
};

void foo ()
{
  B *b = new B;
  b->~A (); 
  // but okay: b->A::~A(); 
}

Reply via email to