Why does g ++ accept a reference type with a missing base type?

I wanted to add a copy constructor to the class, but forgot to add this type. g ++ 5.4.0 compiled the class successfully.

Here's the minimal program that g ++ 5.4.0 compiles and builds successfully.

struct Foo
{ 
   Foo(const&) {}
   Foo() {}
};

int main()
{
   Foo f1;
   Foo f2 = f1;
}

Why does g ++ not report Foo(const&) {}as an error?

+4
source share
1 answer

This seems to be a defect in my g ++ 5.4.0 installation.

Cannot compile with g ++ 6.3 at https://ideone.com/D0vGrw .

I used the same block of code.

struct Foo
{ 
   Foo(const&) {}
   Foo() {}
};

int main()
{
   Foo f1;
   Foo f2 = f1;
}

It also does not compile using g ++ 5.4.0 in Wandbox .

+1
source

Source: https://habr.com/ru/post/1685177/


All Articles