[Bug c++/14140] [3.3/3.4/4.0 Regression] Unwanted call to derived constructor after implicit conversion

giovannibajo at libero dot it gcc-bugzilla@gcc.gnu.org
Wed Oct 13 14:21:00 GMT 2004


------- Additional Comments From giovannibajo at libero dot it  2004-10-13 14:21 -------
Slightly cleaned-up testcase:

--------------------------------------------------
extern "C" int printf(const char* fmt, ...);
extern "C" void abort(void);

struct A {
  A() {}
  A(const A&) { printf("A cctor\n"); }
};


struct B : public A {
  B() {}
  B(const B&) { printf("B cctor\n"); abort(); }
};


struct Wrapper
{
  B* b;
  Wrapper(B* b_) : b(b_) {}

  B& operator*()  const {return *b;}
  operator B&() const {return **this;}
};

void func(A a) {}          // Takes the parameter by value

int main()
{
  B b;
  Wrapper b_wrap(&b);

  printf("\nCalling 'func(b)':\n");
  func(b);

  printf("\nCalling 'func(*b_wrap)':\n");
  func(*b_wrap);

  printf("\nCalling 'func(b_wrap)':\n");
  func(b_wrap);

  return 0;
}
--------------------------------------------------

In short, this should not abort, and does not with ICC, Comeau, or MSVC. This 
is a regression since 2.95 appeared with 3.0.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
      Known to fail|3.3.3 3.2.3 3.4.0 4.0.0     |3.0.4 3.3.3 3.2.3 3.4.0
                   |                            |4.0.0
      Known to work|                            |2.95.3
            Summary|Unwanted call to derived    |[3.3/3.4/4.0 Regression]
                   |constructor after implicit  |Unwanted call to derived
                   |conversion                  |constructor after implicit
                   |                            |conversion
   Target Milestone|---                         |3.4.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14140



More information about the Gcc-bugs mailing list