Skip to content

Commit

Permalink
Add comment documenting why copy is =delete'd, closes #400
Browse files Browse the repository at this point in the history
  • Loading branch information
hsutter committed May 5, 2023
1 parent 768f125 commit 4d034f3
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class widget final

public: [[nodiscard]] auto operator<=>(widget const& that) const -> std::strong_ordering = default;

public: widget(widget const&) = delete;
public: widget(widget const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(widget const&) -> void = delete;
#line 11 "pure2-defaulted-comparisons-and-final-types.cpp2"
};
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/test-results/pure2-requires-clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template<typename T, typename U>
class X {
public: X();

public: X(X const&) = delete;
public: X(X const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(X const&) -> void = delete;
#line 8 "pure2-requires-clauses.cpp2"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class myclass {
private: using str2 = std::string;

public: myclass() = default;
public: myclass(myclass const&) = delete;
public: myclass(myclass const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(myclass const&) -> void = delete;
#line 13 "pure2-type-and-namespace-aliases.cpp2"
};
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/test-results/pure2-types-basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class myclass {
public: static auto g() -> void;

public: nested() = default;
public: nested(nested const&) = delete;
public: nested(nested const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(nested const&) -> void = delete;

#line 51 "pure2-types-basics.cpp2"
Expand All @@ -76,7 +76,7 @@ class myclass {
public: template<auto T, auto U> [[nodiscard]] static auto f3() -> auto;
public: template<cpp2::i8 T, cpp2::i16 U> [[nodiscard]] static auto f4() -> auto;

public: myclass(myclass const&) = delete;
public: myclass(myclass const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(myclass const&) -> void = delete;
#line 58 "pure2-types-basics.cpp2"
};
Expand Down
6 changes: 3 additions & 3 deletions regression-tests/test-results/pure2-types-inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Human {
public: virtual ~Human();

public: Human() = default;
public: Human(Human const&) = delete;
public: Human(Human const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(Human const&) -> void = delete;
#line 4 "pure2-types-inheritance.cpp2"
};
Expand All @@ -44,7 +44,7 @@ namespace N {

public: virtual ~Machine();

public: Machine(Machine const&) = delete;
public: Machine(Machine const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(Machine const&) -> void = delete;

#line 10 "pure2-types-inheritance.cpp2"
Expand Down Expand Up @@ -72,7 +72,7 @@ class Cyborg: public Cyborg_name_as_base, public Human, public Cyborg_address_as

public: ~Cyborg();

public: Cyborg(Cyborg const&) = delete;
public: Cyborg(Cyborg const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(Cyborg const&) -> void = delete;

#line 36 "pure2-types-inheritance.cpp2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class X {
// X::exx member function description here
public: auto exx(cpp2::in<int> count) const -> void;

public: X(X const&) = delete;
public: X(X const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(X const&) -> void = delete;


Expand All @@ -71,7 +71,7 @@ class Y {

public: auto why(cpp2::in<int> count) const -> void;

public: Y(Y const&) = delete;
public: Y(Y const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(Y const&) -> void = delete;

#line 53 "pure2-types-order-independence-and-nesting.cpp2"
Expand All @@ -85,14 +85,14 @@ template<typename T, typename U> class A {
public: template<typename V, int J, typename W> static auto f(W const& w) -> void;

public: B() = default;
public: B(B const&) = delete;
public: B(B const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(B const&) -> void = delete;

#line 61 "pure2-types-order-independence-and-nesting.cpp2"
};

public: A() = default;
public: A(A const&) = delete;
public: A(A const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(A const&) -> void = delete;
#line 62 "pure2-types-order-independence-and-nesting.cpp2"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class my_integer {

public: [[nodiscard]] auto operator<=>(my_integer const& that) const -> std::strong_ordering = default;

public: my_integer(my_integer const&) = delete;
public: my_integer(my_integer const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(my_integer const&) -> void = delete;
#line 5 "pure2-types-ordering-via-meta-functions.cpp2"
};
Expand All @@ -48,7 +48,7 @@ class case_insensitive_string {

public: [[nodiscard]] auto operator<=>(case_insensitive_string const& that) const -> std::weak_ordering = default;

public: case_insensitive_string(case_insensitive_string const&) = delete;
public: case_insensitive_string(case_insensitive_string const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(case_insensitive_string const&) -> void = delete;
#line 10 "pure2-types-ordering-via-meta-functions.cpp2"
};
Expand All @@ -61,7 +61,7 @@ class person_in_family_tree {

public: [[nodiscard]] auto operator<=>(person_in_family_tree const& that) const -> std::partial_ordering = default;

public: person_in_family_tree(person_in_family_tree const&) = delete;
public: person_in_family_tree(person_in_family_tree const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(person_in_family_tree const&) -> void = delete;
#line 15 "pure2-types-ordering-via-meta-functions.cpp2"
};
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cppfront compiler v0.2.1 Build 8429:1224
cppfront compiler v0.2.1 Build 8505:0902
Copyright(c) Herb Sutter All rights reserved

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
1 change: 1 addition & 0 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ class cmdline_processor
ret += ":";
ret += b.substr(0,2);
ret += b.substr(3,2);
for (auto& c : ret) { if (c == ' ') { c = '0'; } }
return ret;
};

Expand Down
2 changes: 1 addition & 1 deletion source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5097,7 +5097,7 @@ class cppfront
// If no 'that' constructor was defined, disable copy/move
// so that Cpp1 doesn't silently generate it anyway
if (!found_that_constructor) {
printer.print_extra( prefix + id + "(" + id + " const&) = delete;" );
printer.print_extra( prefix + id + "(" + id + " const&) = delete; /* No 'that' constructor, suppress copy */" );
printer.print_extra( prefix + "auto operator=(" + id + " const&) -> void = delete;" );
}

Expand Down

0 comments on commit 4d034f3

Please sign in to comment.