Remove default constructor from IndexBase (#2598)

There were some notes about default constructors being required in parse_tree.h, but they don't seem to be. Removing the default constructor forces the explicit `::Invalid` where there's no value immediately being assigned, which works fine for existing code. I think this actually reduces the chance of accidents more than the prior default-construct-as-invalid approach.
This commit is contained in:
Jon Ross-Perkins
2023-02-10 12:00:50 -08:00
committed by GitHub
parent aa307b1144
commit b76bc875c4
7 changed files with 28 additions and 30 deletions
+4 -6
View File
@@ -249,7 +249,8 @@ struct ParseTree::Node : public ComparableIndexBase {
using ComparableIndexBase::ComparableIndexBase;
};
constexpr ParseTree::Node ParseTree::Node::Invalid;
constexpr ParseTree::Node ParseTree::Node::Invalid =
ParseTree::Node(ParseTree::Node::InvalidIndex);
// A random-access iterator to the depth-first postorder sequence of parse nodes
// in the parse tree. It produces `ParseTree::Node` objects which are opaque
@@ -259,10 +260,7 @@ class ParseTree::PostorderIterator
std::random_access_iterator_tag, Node,
int, Node*, Node> {
public:
// Default construction is only provided to satisfy iterator requirements. It
// produces an unusable iterator, and you must assign a valid iterator to it
// before performing any operations.
explicit PostorderIterator() = default;
PostorderIterator() = delete;
auto operator==(const PostorderIterator& rhs) const -> bool {
return node_ == rhs.node_;
@@ -312,7 +310,7 @@ class ParseTree::SiblingIterator
: public llvm::iterator_facade_base<
SiblingIterator, std::forward_iterator_tag, Node, int, Node*, Node> {
public:
explicit SiblingIterator() = default;
explicit SiblingIterator() = delete;
auto operator==(const SiblingIterator& rhs) const -> bool {
return node_ == rhs.node_;