mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:54:47 +01:00
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:
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user