aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-07-29 11:16:28 +1000
committerNeil <nyamatongwe@gmail.com>2022-07-29 11:16:28 +1000
commite030b1d56785405cb35531758d603be88af9b487 (patch)
tree9a428393f7963d50a0b7557e7c77ac1be37c7bb3
parent6e6641d4733903d3c365fd9348f3656ff7000ddf (diff)
downloadscintilla-mirror-e030b1d56785405cb35531758d603be88af9b487.tar.gz
Apply rule-of-zero to delete standard methods where possible as handled by
contained types. This allows flexibility as most lower-level data types can be moved and SplitVector and Partitioning of non-move-only types may be copied. CellBuffer still needs destructor due to incomplete type so retains all standard operations.
-rw-r--r--src/CellBuffer.cxx9
-rw-r--r--src/CellBuffer.h19
-rw-r--r--src/ContractionState.cxx9
-rw-r--r--src/Partitioning.h9
-rw-r--r--src/PerLine.cxx19
-rw-r--r--src/PerLine.h36
-rw-r--r--src/RunStyles.cxx4
-rw-r--r--src/RunStyles.h6
-rw-r--r--src/SparseVector.h6
-rw-r--r--src/SplitVector.h9
-rw-r--r--src/UniqueString.cxx2
-rw-r--r--src/UniqueString.h7
-rw-r--r--test/unit/testPartitioning.cxx24
-rw-r--r--test/unit/testPerLine.cxx24
-rw-r--r--test/unit/testRunStyles.cxx46
-rw-r--r--test/unit/testSparseVector.cxx45
-rw-r--r--test/unit/testSplitVector.cxx47
17 files changed, 190 insertions, 131 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index b84372cf2..9a509f2eb 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -329,9 +329,6 @@ Action::Action() noexcept {
mayCoalesce = false;
}
-Action::~Action() {
-}
-
void Action::Create(ActionType at_, Sci::Position position_, const char *data_, Sci::Position lenData_, bool mayCoalesce_) {
data = nullptr;
position = position_;
@@ -379,9 +376,6 @@ UndoHistory::UndoHistory() {
actions[currentAction].Create(ActionType::start);
}
-UndoHistory::~UndoHistory() {
-}
-
void UndoHistory::EnsureUndoRoom() {
// Have to test that there is room for 2 more actions in the array
// as two actions may be created by the calling function
@@ -598,8 +592,7 @@ CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :
plv = std::make_unique<LineVector<int>>();
}
-CellBuffer::~CellBuffer() {
-}
+CellBuffer::~CellBuffer() noexcept = default;
char CellBuffer::CharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index d8914d7ba..727e14944 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -39,13 +39,6 @@ public:
bool mayCoalesce;
Action() noexcept;
- // Deleted so Action objects can not be copied.
- Action(const Action &other) = delete;
- Action &operator=(const Action &other) = delete;
- Action &operator=(const Action &&other) = delete;
- // Move constructor allows vector to be resized without reallocating.
- Action(Action &&other) noexcept = default;
- ~Action();
void Create(ActionType at_, Sci::Position position_=0, const char *data_=nullptr, Sci::Position lenData_=0, bool mayCoalesce_=true);
void Clear() noexcept;
};
@@ -65,12 +58,6 @@ class UndoHistory {
public:
UndoHistory();
- // Deleted so UndoHistory objects can not be copied.
- UndoHistory(const UndoHistory &) = delete;
- UndoHistory(UndoHistory &&) = delete;
- void operator=(const UndoHistory &) = delete;
- void operator=(UndoHistory &&) = delete;
- ~UndoHistory();
const char *AppendAction(ActionType at, Sci::Position position, const char *data, Sci::Position lengthData, bool &startSequence, bool mayCoalesce=true);
@@ -163,9 +150,9 @@ public:
// Deleted so CellBuffer objects can not be copied.
CellBuffer(const CellBuffer &) = delete;
CellBuffer(CellBuffer &&) = delete;
- void operator=(const CellBuffer &) = delete;
- void operator=(CellBuffer &&) = delete;
- ~CellBuffer();
+ CellBuffer &operator=(const CellBuffer &) = delete;
+ CellBuffer &operator=(CellBuffer &&) = delete;
+ ~CellBuffer() noexcept;
/// Retrieving positions outside the range of the buffer works and returns 0
char CharAt(Sci::Position position) const noexcept;
diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx
index b64e044ab..b36e1ebd8 100644
--- a/src/ContractionState.cxx
+++ b/src/ContractionState.cxx
@@ -59,12 +59,6 @@ class ContractionState final : public IContractionState {
public:
ContractionState() noexcept;
- // Deleted so ContractionState objects can not be copied.
- ContractionState(const ContractionState &) = delete;
- void operator=(const ContractionState &) = delete;
- ContractionState(ContractionState &&) = delete;
- void operator=(ContractionState &&) = delete;
- ~ContractionState() override;
void Clear() noexcept override;
@@ -102,9 +96,6 @@ ContractionState<LINE>::ContractionState() noexcept : linesInDocument(1) {
}
template <typename LINE>
-ContractionState<LINE>::~ContractionState() = default;
-
-template <typename LINE>
void ContractionState<LINE>::EnsureData() {
if (OneToOne()) {
visible = std::make_unique<RunStyles<LINE, char>>();
diff --git a/src/Partitioning.h b/src/Partitioning.h
index 2836b66dd..17bc1998e 100644
--- a/src/Partitioning.h
+++ b/src/Partitioning.h
@@ -78,15 +78,6 @@ public:
body.Insert(1, 0); // This is the end of the first partition and will be the start of the second
}
- // Deleted so Partitioning objects can not be copied.
- Partitioning(const Partitioning &) = delete;
- Partitioning(Partitioning &&) = delete;
- Partitioning &operator=(const Partitioning &) = delete;
- Partitioning &operator=(Partitioning &&) = default;
-
- ~Partitioning() {
- }
-
T Partitions() const noexcept {
return static_cast<T>(body.Length())-1;
}
diff --git a/src/PerLine.cxx b/src/PerLine.cxx
index f3fddcf27..78f7c7dc5 100644
--- a/src/PerLine.cxx
+++ b/src/PerLine.cxx
@@ -34,10 +34,6 @@ using namespace Scintilla::Internal;
MarkerHandleSet::MarkerHandleSet() {
}
-MarkerHandleSet::~MarkerHandleSet() {
- mhList.clear();
-}
-
bool MarkerHandleSet::Empty() const noexcept {
return mhList.empty();
}
@@ -93,9 +89,6 @@ void MarkerHandleSet::CombineWith(MarkerHandleSet *other) noexcept {
mhList.splice_after(mhList.before_begin(), other->mhList);
}
-LineMarkers::~LineMarkers() {
-}
-
void LineMarkers::Init() {
markers.DeleteAll();
}
@@ -219,9 +212,6 @@ void LineMarkers::DeleteMarkFromHandle(int markerHandle) {
}
}
-LineLevels::~LineLevels() {
-}
-
void LineLevels::Init() {
levels.DeleteAll();
}
@@ -281,9 +271,6 @@ int LineLevels::GetLevel(Sci::Line line) const noexcept {
}
}
-LineState::~LineState() {
-}
-
void LineState::Init() {
lineStates.DeleteAll();
}
@@ -355,9 +342,6 @@ std::unique_ptr<char[]>AllocateAnnotation(size_t length, int style) {
}
-LineAnnotation::~LineAnnotation() {
-}
-
bool LineAnnotation::Empty() const noexcept {
return annotations.Length() == 0;
}
@@ -482,9 +466,6 @@ int LineAnnotation::Lines(Sci::Line line) const noexcept {
return 0;
}
-LineTabstops::~LineTabstops() {
-}
-
void LineTabstops::Init() {
tabstops.DeleteAll();
}
diff --git a/src/PerLine.h b/src/PerLine.h
index ef9e36932..5b57dcaa9 100644
--- a/src/PerLine.h
+++ b/src/PerLine.h
@@ -28,12 +28,6 @@ class MarkerHandleSet {
public:
MarkerHandleSet();
- // Deleted so MarkerHandleSet objects can not be copied.
- MarkerHandleSet(const MarkerHandleSet &) = delete;
- MarkerHandleSet(MarkerHandleSet &&) = delete;
- void operator=(const MarkerHandleSet &) = delete;
- void operator=(MarkerHandleSet &&) = delete;
- ~MarkerHandleSet();
bool Empty() const noexcept;
int MarkValue() const noexcept; ///< Bit set of marker numbers.
bool Contains(int handle) const noexcept;
@@ -51,12 +45,6 @@ class LineMarkers : public PerLine {
public:
LineMarkers() : handleCurrent(0) {
}
- // Deleted so LineMarkers objects can not be copied.
- LineMarkers(const LineMarkers &) = delete;
- LineMarkers(LineMarkers &&) = delete;
- void operator=(const LineMarkers &) = delete;
- void operator=(LineMarkers &&) = delete;
- ~LineMarkers() override;
void Init() override;
void InsertLine(Sci::Line line) override;
void InsertLines(Sci::Line line, Sci::Line lines) override;
@@ -78,12 +66,6 @@ class LineLevels : public PerLine {
public:
LineLevels() {
}
- // Deleted so LineLevels objects can not be copied.
- LineLevels(const LineLevels &) = delete;
- LineLevels(LineLevels &&) = delete;
- void operator=(const LineLevels &) = delete;
- void operator=(LineLevels &&) = delete;
- ~LineLevels() override;
void Init() override;
void InsertLine(Sci::Line line) override;
void InsertLines(Sci::Line line, Sci::Line lines) override;
@@ -100,12 +82,6 @@ class LineState : public PerLine {
public:
LineState() {
}
- // Deleted so LineState objects can not be copied.
- LineState(const LineState &) = delete;
- LineState(LineState &&) = delete;
- void operator=(const LineState &) = delete;
- void operator=(LineState &&) = delete;
- ~LineState() override;
void Init() override;
void InsertLine(Sci::Line line) override;
void InsertLines(Sci::Line line, Sci::Line lines) override;
@@ -121,12 +97,6 @@ class LineAnnotation : public PerLine {
public:
LineAnnotation() {
}
- // Deleted so LineAnnotation objects can not be copied.
- LineAnnotation(const LineAnnotation &) = delete;
- LineAnnotation(LineAnnotation &&) = delete;
- void operator=(const LineAnnotation &) = delete;
- void operator=(LineAnnotation &&) = delete;
- ~LineAnnotation() override;
[[nodiscard]] bool Empty() const noexcept;
void Init() override;
@@ -153,12 +123,6 @@ class LineTabstops : public PerLine {
public:
LineTabstops() {
}
- // Deleted so LineTabstops objects can not be copied.
- LineTabstops(const LineTabstops &) = delete;
- LineTabstops(LineTabstops &&) = delete;
- void operator=(const LineTabstops &) = delete;
- void operator=(LineTabstops &&) = delete;
- ~LineTabstops() override;
void Init() override;
void InsertLine(Sci::Line line) override;
void InsertLines(Sci::Line line, Sci::Line lines) override;
diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx
index 37c76f921..5985bc960 100644
--- a/src/RunStyles.cxx
+++ b/src/RunStyles.cxx
@@ -86,10 +86,6 @@ RunStyles<DISTANCE, STYLE>::RunStyles() {
}
template <typename DISTANCE, typename STYLE>
-RunStyles<DISTANCE, STYLE>::~RunStyles() {
-}
-
-template <typename DISTANCE, typename STYLE>
DISTANCE RunStyles<DISTANCE, STYLE>::Length() const noexcept {
return starts.PositionFromPartition(starts.Partitions());
}
diff --git a/src/RunStyles.h b/src/RunStyles.h
index 76d75d75a..44367adf7 100644
--- a/src/RunStyles.h
+++ b/src/RunStyles.h
@@ -34,12 +34,6 @@ private:
void RemoveRunIfSameAsPrevious(DISTANCE run);
public:
RunStyles();
- // Deleted so RunStyles objects can not be copied.
- RunStyles(const RunStyles &) = delete;
- RunStyles(RunStyles &&) = delete;
- void operator=(const RunStyles &) = delete;
- void operator=(RunStyles &&) = delete;
- ~RunStyles();
DISTANCE Length() const noexcept;
STYLE ValueAt(DISTANCE position) const noexcept;
DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const noexcept;
diff --git a/src/SparseVector.h b/src/SparseVector.h
index cc3fe1448..f8c35fdc5 100644
--- a/src/SparseVector.h
+++ b/src/SparseVector.h
@@ -31,12 +31,6 @@ public:
values = SplitVector<T>();
values.InsertEmpty(0, 2);
}
- // Deleted so SparseVector objects can not be copied.
- SparseVector(const SparseVector &) = delete;
- SparseVector(SparseVector &&) = delete;
- void operator=(const SparseVector &) = delete;
- void operator=(SparseVector &&) = delete;
- ~SparseVector() noexcept = default;
Sci::Position Length() const noexcept {
return starts.Length();
}
diff --git a/src/SplitVector.h b/src/SplitVector.h
index 6c5514a22..19b854f5a 100644
--- a/src/SplitVector.h
+++ b/src/SplitVector.h
@@ -74,15 +74,6 @@ public:
SplitVector(size_t growSize_=8) : empty(), lengthBody(0), part1Length(0), gapLength(0), growSize(growSize_) {
}
- // Deleted so SplitVector objects can not be copied.
- SplitVector(const SplitVector &) = delete;
- SplitVector(SplitVector &&) = delete;
- SplitVector &operator=(const SplitVector &) = delete;
- SplitVector &operator=(SplitVector &&) = default;
-
- ~SplitVector() {
- }
-
size_t GetGrowSize() const noexcept {
return growSize;
}
diff --git a/src/UniqueString.cxx b/src/UniqueString.cxx
index 0550a0b8c..4c5b4b231 100644
--- a/src/UniqueString.cxx
+++ b/src/UniqueString.cxx
@@ -30,8 +30,6 @@ UniqueString UniqueStringCopy(const char *text) {
UniqueStringSet::UniqueStringSet() = default;
-UniqueStringSet::~UniqueStringSet() noexcept = default;
-
void UniqueStringSet::Clear() noexcept {
strings.clear();
}
diff --git a/src/UniqueString.h b/src/UniqueString.h
index 8d611992c..c5617e1c9 100644
--- a/src/UniqueString.h
+++ b/src/UniqueString.h
@@ -30,13 +30,6 @@ private:
std::vector<UniqueString> strings;
public:
UniqueStringSet();
- // UniqueStringSet objects can not be copied.
- UniqueStringSet(const UniqueStringSet &) = delete;
- UniqueStringSet &operator=(const UniqueStringSet &) = delete;
- // UniqueStringSet objects can be moved.
- UniqueStringSet(UniqueStringSet &&) = default;
- UniqueStringSet &operator=(UniqueStringSet &&) = default;
- ~UniqueStringSet() noexcept;
void Clear() noexcept;
const char *Save(const char *text);
};
diff --git a/test/unit/testPartitioning.cxx b/test/unit/testPartitioning.cxx
index fc55b4da1..5eef60c39 100644
--- a/test/unit/testPartitioning.cxx
+++ b/test/unit/testPartitioning.cxx
@@ -27,6 +27,30 @@ static const int testArray[lengthTestArray] = {3, 4, 5, 6, 7, 8, 9, 10};
// Test Partitioning.
+TEST_CASE("CompileCopying Partitioning") {
+
+ // These are compile-time tests to check that basic copy and move
+ // operations are defined correctly.
+
+ SECTION("CopyingMoving") {
+ Partitioning<int> s;
+ Partitioning<int> s2;
+
+ // Copy constructor
+ Partitioning<int> sa(s);
+ // Copy assignment
+ Partitioning<int> sb;
+ sb = s;
+
+ // Move constructor
+ Partitioning<int> sc(std::move(s));
+ // Move assignment
+ Partitioning<int> sd;
+ sd = (std::move(s2));
+ }
+
+}
+
TEST_CASE("Partitioning") {
Partitioning<Sci::Position> part;
diff --git a/test/unit/testPerLine.cxx b/test/unit/testPerLine.cxx
index 74881f40e..d9cf11ac6 100644
--- a/test/unit/testPerLine.cxx
+++ b/test/unit/testPerLine.cxx
@@ -31,6 +31,30 @@ constexpr int FoldBase = static_cast<int>(Scintilla::FoldLevel::Base);
// Test MarkerHandleSet.
+TEST_CASE("CompileCopying MarkerHandleSet") {
+
+ // These are compile-time tests to check that basic copy and move
+ // operations are defined correctly.
+
+ SECTION("CopyingMoving") {
+ MarkerHandleSet s;
+ MarkerHandleSet s2;
+
+ // Copy constructor
+ MarkerHandleSet sa(s);
+ // Copy assignment
+ MarkerHandleSet sb;
+ sb = s;
+
+ // Move constructor
+ MarkerHandleSet sc(std::move(s));
+ // Move assignment
+ MarkerHandleSet sd;
+ sd = (std::move(s2));
+ }
+
+}
+
TEST_CASE("MarkerHandleSet") {
MarkerHandleSet mhs;
diff --git a/test/unit/testRunStyles.cxx b/test/unit/testRunStyles.cxx
index 92e6b9ae8..74be54dc7 100644
--- a/test/unit/testRunStyles.cxx
+++ b/test/unit/testRunStyles.cxx
@@ -25,6 +25,52 @@ using namespace Scintilla::Internal;
// Test RunStyles.
+using UniqueInt = std::unique_ptr<int>;
+
+TEST_CASE("CompileCopying RunStyles") {
+
+ // These are compile-time tests to check that basic copy and move
+ // operations are defined correctly.
+
+ SECTION("CopyingMoving") {
+ RunStyles<int, int> s;
+ RunStyles<int, int> s2;
+
+ // Copy constructor
+ RunStyles<int, int> sa(s);
+ // Copy assignment fails
+ RunStyles<int, int> sb;
+ sb = s;
+
+ // Move constructor
+ RunStyles<int, int> sc(std::move(s));
+ // Move assignment
+ RunStyles<int, int> sd;
+ sd = (std::move(s2));
+ }
+
+#if defined(SHOW_COPY_BUILD_FAILURES)
+ // It should be reasonable to instantiate RunStyles where STYLE is move-only but fails
+ SECTION("MoveOnly") {
+ RunStyles<int, UniqueInt> s;
+
+ // Copy is not defined for std::unique_ptr
+ // Copy constructor fails
+ RunStyles<int, UniqueInt> sa(s);
+ // Copy assignment fails
+ RunStyles<int, UniqueInt> sb;
+ sb = s;
+
+ // Move constructor fails
+ RunStyles<int, UniqueInt> sc(std::move(s));
+ // Move assignment fails
+ RunStyles<int, UniqueInt> sd;
+ sd = (std::move(s));
+ }
+#endif
+
+}
+
namespace Scintilla::Internal { // Xcode clang 9.0 doesn't like this when in the unnamed namespace
bool operator==(const FillResult<int> &fra, const FillResult<int> &frb) {
return fra.changed == frb.changed &&
diff --git a/test/unit/testSparseVector.cxx b/test/unit/testSparseVector.cxx
index 763fa027c..3a784d4c2 100644
--- a/test/unit/testSparseVector.cxx
+++ b/test/unit/testSparseVector.cxx
@@ -27,6 +27,51 @@ using namespace Scintilla::Internal;
// Test SparseVector.
+using UniqueInt = std::unique_ptr<int>;
+
+TEST_CASE("CompileCopying SparseVector") {
+
+ // These are compile-time tests to check that basic copy and move
+ // operations are defined correctly.
+
+ SECTION("CopyingMoving") {
+ SparseVector<int> s;
+ SparseVector<int> s2;
+
+ // Copy constructor
+ SparseVector<int> sa(s);
+ // Copy assignment
+ SparseVector<int> sb;
+ sb = s;
+
+ // Move constructor
+ SparseVector<int> sc(std::move(s));
+ // Move assignment
+ SparseVector<int> sd;
+ sd = (std::move(s2));
+ }
+
+ SECTION("MoveOnly") {
+ SparseVector<UniqueInt> s;
+
+#if defined(SHOW_COPY_BUILD_FAILURES)
+ // Copy is not defined for std::unique_ptr
+ // Copy constructor fails
+ SparseVector<UniqueInt> sa(s);
+ // Copy assignment fails
+ SparseVector<UniqueInt> sb;
+ sb = s;
+#endif
+
+ // Move constructor
+ SparseVector<UniqueInt> sc(std::move(s));
+ // Move assignment
+ SparseVector<UniqueInt> sd;
+ sd = (std::move(s));
+ }
+
+}
+
// Helper to produce a string representation of a SparseVector<const char *>
// to simplify checks.
static std::string Representation(const SparseVector<UniqueString> &st) {
diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx
index aa855f1b1..c836a4ffe 100644
--- a/test/unit/testSplitVector.cxx
+++ b/test/unit/testSplitVector.cxx
@@ -23,6 +23,53 @@ using namespace Scintilla::Internal;
// Test SplitVector.
+using UniqueInt = std::unique_ptr<int>;
+
+// Test SplitVector.
+
+TEST_CASE("CompileCopying SplitVector") {
+
+ // These are compile-time tests to check that basic copy and move
+ // operations are defined correctly.
+
+ SECTION("CopyingMoving") {
+ SplitVector<int> s;
+ SplitVector<int> s2;
+
+ // Copy constructor fails
+ SplitVector<int> sa(s);
+ // Copy assignment fails
+ SplitVector<int> sb;
+ sb = s;
+
+ // Move constructor fails
+ SplitVector<int> sc(std::move(s));
+ // Move assignment fails
+ SplitVector<int> sd;
+ sd = (std::move(s2));
+ }
+
+ SECTION("MoveOnly") {
+ SplitVector<UniqueInt> s;
+
+#if defined(SHOW_COPY_BUILD_FAILURES)
+ // Copy is not defined for std::unique_ptr
+ // Copy constructor fails
+ SplitVector<UniqueInt> sa(s);
+ // Copy assignment fails
+ SplitVector<UniqueInt> sb;
+ sb = s;
+#endif
+
+ // Move constructor fails
+ SplitVector<UniqueInt> sc(std::move(s));
+ // Move assignment fails
+ SplitVector<UniqueInt> sd;
+ sd = (std::move(s));
+ }
+
+}
+
struct StringSetHolder {
SplitVector<std::string> sa;
bool Check() const noexcept {