Jonathan Nieder wrote:

> @@ -161,9 +168,10 @@ struct CUPT_API ArchitecturedRelationExpression: public 
> vector< ArchitecturedRel
>        * representation
>        */
>       ArchitecturedRelationExpression(pair< string::const_iterator, 
> string::const_iterator > input);
> -     /// copy constructor from rvalue reference
> -     ArchitecturedRelationExpression(ArchitecturedRelationExpression&&);
> +     ArchitecturedRelationExpression(ArchitecturedRelationExpression&&) = 
> default;
> +     ArchitecturedRelationExpression(const ArchitecturedRelationExpression&) 
> = default;
> +     ArchitecturedRelationExpression& 
> operator=(ArchitecturedRelationExpression&&) = default;
> +     ArchitecturedRelationExpression& operator=(const 
> ArchitecturedRelationExpression&) = default;
> -     /// destructor

Unrelated line deletion snuck in. :(

[...]
> @@ -191,8 +199,8 @@ struct CUPT_API RelationLine: public vector< 
> RelationExpression >
>        * representation
>        */
>       explicit RelationLine(pair< string::const_iterator, 
> string::const_iterator > input);
> -     /// operator= from the rvalue reference
>       RelationLine& operator=(RelationLine&& other);
> +     RelationLine& operator=(const RelationLine&) = default;

This works, but it isn't consistent with the others (I guess gcc doesn't
mind not being able to find the "operator=(RelationLine&&)" definition
and there was no code that needs to call the "RelationLine(const
RelationLine&)" constructor yet).

Corrected patch attached.
From: Jonathan Nieder <jrnie...@gmail.com>
Date: Sun, 30 Oct 2011 16:20:17 -0500
Subject: lib: do not suppress default copy constructors and assignment operators

Building cupt with g++ 4.6 produces some errors due to missing
copy-assignment operators and copy constructors.

The C++ standard (n3242, section special.class.copy "Copying and
moving class objects", paragraph 8) explains:

        If the class definition does not explicitly declare a copy
        constructor, there is no user-declared move constructor, and
        there is no user-declared move assignment operator, a copy
        constructor is implicitly declared as defaulted.

In other words, if we declare _any_ move constructor or move
assignment operator, the default copy constructor is not guaranteed to
be present.  (Likewise for the default copy-assignment operator.)

Worse, most of the move operations we provide are superfluous, since
they just call std::move to convert "operand.member" from an lvalue to
an xvalue, and members of an object referred to by rvalue reference
are already xvalues.  Simplify by using the implicit definitions that
accomplish the same thing (but to be cautious, explicitly declare that
we are doing so).

The only exception is cupt::internal::PackageEntry, whose rvalue
operations explicitly call std::vector::swap.  That is probably not
needed, either, since std::vector provides rvalue operations, too, but
to be conservative, this patch leaves it alone.

Signed-off-by: Jonathan Nieder <jrnie...@gmail.com>
---
 cpp/lib/include/cupt/cache/relation.hpp          |   35 +++++++++++++++-------
 cpp/lib/src/cache/relation.cpp                   |   15 ---------
 cpp/lib/src/internal/nativeresolver/solution.hpp |    2 +
 3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/cpp/lib/include/cupt/cache/relation.hpp 
b/cpp/lib/include/cupt/cache/relation.hpp
index f6f1f965..9d512a7c 100644
--- a/cpp/lib/include/cupt/cache/relation.hpp
+++ b/cpp/lib/include/cupt/cache/relation.hpp
@@ -56,8 +56,10 @@ struct CUPT_API Relation
         * @param input pair of begin iterator and end iterator of stringified 
relation
         */
        explicit Relation(pair< string::const_iterator, string::const_iterator 
> input);
-       /// constructor from rvalue reference
-       Relation(Relation&&);
+       Relation(Relation&&) = default;
+       Relation(const Relation&) = default;
+       Relation& operator=(Relation&&) = default;
+       Relation& operator=(const Relation&) = default;
        /// destructor
        virtual ~Relation();
        /// gets the string reprentation
@@ -101,7 +103,10 @@ struct CUPT_API ArchitecturedRelation: public Relation
         * architectured relation
         */
        ArchitecturedRelation(pair< string::const_iterator, 
string::const_iterator > input);
-       ArchitecturedRelation(ArchitecturedRelation&&);
+       ArchitecturedRelation(ArchitecturedRelation&&) = default;
+       ArchitecturedRelation(const ArchitecturedRelation&) = default;
+       ArchitecturedRelation& operator=(ArchitecturedRelation&&) = default;
+       ArchitecturedRelation& operator=(const ArchitecturedRelation&) = 
default;
        string toString() const;
 };
 
@@ -131,8 +136,10 @@ struct CUPT_API RelationExpression: public vector< 
Relation >
         * representation
         */
        explicit RelationExpression(pair< string::const_iterator, 
string::const_iterator > input);
-       /// copy constructor from rvalue reference
-       RelationExpression(RelationExpression&&);
+       RelationExpression(RelationExpression&&) = default;
+       RelationExpression(const RelationExpression&) = default;
+       RelationExpression& operator=(RelationExpression&&) = default;
+       RelationExpression& operator=(const RelationExpression&) = default;
        /// destructor
        virtual ~RelationExpression();
 };
@@ -161,8 +168,10 @@ struct CUPT_API ArchitecturedRelationExpression: public 
vector< ArchitecturedRel
         * representation
         */
        ArchitecturedRelationExpression(pair< string::const_iterator, 
string::const_iterator > input);
-       /// copy constructor from rvalue reference
-       ArchitecturedRelationExpression(ArchitecturedRelationExpression&&);
+       ArchitecturedRelationExpression(ArchitecturedRelationExpression&&) = 
default;
+       ArchitecturedRelationExpression(const ArchitecturedRelationExpression&) 
= default;
+       ArchitecturedRelationExpression& 
operator=(ArchitecturedRelationExpression&&) = default;
+       ArchitecturedRelationExpression& operator=(const 
ArchitecturedRelationExpression&) = default;
        /// destructor
        virtual ~ArchitecturedRelationExpression();
 };
@@ -191,8 +200,10 @@ struct CUPT_API RelationLine: public vector< 
RelationExpression >
         * representation
         */
        explicit RelationLine(pair< string::const_iterator, 
string::const_iterator > input);
-       /// operator= from the rvalue reference
-       RelationLine& operator=(RelationLine&& other);
+       RelationLine(RelationLine&&) = default;
+       RelationLine(const RelationLine&) = default;
+       RelationLine& operator=(RelationLine&&) = default;
+       RelationLine& operator=(const RelationLine&) = default;
        /// destructor
        virtual ~RelationLine();
 };
@@ -221,8 +232,10 @@ struct CUPT_API ArchitecturedRelationLine: public vector< 
ArchitecturedRelationE
         * representation
         */
        explicit ArchitecturedRelationLine(pair< string::const_iterator, 
string::const_iterator > input);
-       /// operator= from the rvalue reference
-       ArchitecturedRelationLine& operator=(ArchitecturedRelationLine&&);
+       ArchitecturedRelationLine(ArchitecturedRelationLine&&) = default;
+       ArchitecturedRelationLine(const ArchitecturedRelationLine&) = default;
+       ArchitecturedRelationLine& operator=(ArchitecturedRelationLine&&) = 
default;
+       ArchitecturedRelationLine& operator=(const ArchitecturedRelationLine&) 
= default;
        /// converts to RelationLine given system architecture
        /**
         * Filters ArchitecturedRelationLine using binary system architecture.
diff --git a/cpp/lib/src/cache/relation.cpp b/cpp/lib/src/cache/relation.cpp
index ce7ed61c..5f721cda 100644
--- a/cpp/lib/src/cache/relation.cpp
+++ b/cpp/lib/src/cache/relation.cpp
@@ -160,12 +160,6 @@ Relation::Relation(const string& unparsed)
        __init(unparsed.begin(), unparsed.end());
 }
 
-Relation::Relation(Relation&& other)
-       : packageName(std::move(other.packageName)),
-       relationType(other.relationType),
-       versionString(std::move(other.versionString))
-{}
-
 Relation::~Relation()
 {}
 
@@ -248,11 +242,6 @@ ArchitecturedRelation::ArchitecturedRelation(
        __init(std::find(input.first, input.second, '['), input.second);
 }
 
-ArchitecturedRelation::ArchitecturedRelation(ArchitecturedRelation&& other)
-       : Relation(static_cast< Relation&& >(other)),
-       architectureFilters(std::move(other.architectureFilters))
-{}
-
 string ArchitecturedRelation::toString() const
 {
        static const string openingBracket = "[";
@@ -417,10 +406,6 @@ RelationExpressionType::RelationExpressionType(const 
string& expression) \
        __init(expression.begin(), expression.end()); \
 } \
 \
-RelationExpressionType::RelationExpressionType(RelationExpressionType&& other) 
\
-       : vector< UnderlyingElement >(std::move(other)) \
-{} \
-\
 RelationExpressionType::~RelationExpressionType() \
 {} \
  \
diff --git a/cpp/lib/src/internal/nativeresolver/solution.hpp 
b/cpp/lib/src/internal/nativeresolver/solution.hpp
index 88778650..6fe07930 100644
--- a/cpp/lib/src/internal/nativeresolver/solution.hpp
+++ b/cpp/lib/src/internal/nativeresolver/solution.hpp
@@ -77,8 +77,10 @@ struct PackageEntry
 
        PackageEntry();
        PackageEntry(PackageEntry&&);
+       PackageEntry(const PackageEntry&) = default;
 
        PackageEntry& operator=(PackageEntry&&);
+       PackageEntry& operator=(const PackageEntry&) = default;
 };
 
 class PackageEntryMap;
-- 
1.7.7.1

Reply via email to