Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

What does the Standard say about these different behaviors?

$
0
0

The following code shows different behaviors for clang++ and VS2013, both with error messages.

#include <iostream>

class Shape {
public:
    Shape(const Shape&) = delete;
    Shape& operator=(const Shape&) =delete;
    Shape(Shape&&) =delete; //no move operations
    Shape& operator=(Shape&&) =delete;
    virtual ~Shape() = default;
protected:
    Shape() = default;
};

class Circle: public Shape
{
    public:
    Circle(int i) : a(i) {}
    Circle* clone() const { return new Circle(*this); }
    int a;
};

int main()
{
    Circle a(1);
    Circle* p = a.clone();
    std::cout << a.a << "  " << p->a << '\n';
}

VS2013 complains about Shape's copy constructor which is deleted and says that the diagnostic occurred in the compiler generated copy constructor forCircle, which derives from Shape.

clang++ complains about  Circle's implicitly deleted copy constructor which is being called by theclone() function in Circle.

Which one shows the correct behavior according to the C++11 Standard?



Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>