Closed aurelw closed 3 years ago
I have seen this error before, I think it had to do with the compiler version. What gcc version are you using? Maybe you could try a later GCC version or use clang? I usually use clang-9 or clang-10.
Also, try using the -fpermissive
flag
I use GCC 10.2.1.
My project also ships on windows so at some point I will have to compile this with MSVC 2019 (14.29) as well.
The -fpermissive flag does the trick for now, though I still get a lot of warnings. Thanks.
Also, if it is straight forward, I would suggest some refactoring, so at least the header compiles without -fpermissive (for the actual library build it's irrelevant). In my case for e.g. I would have troubles containing the inclusion of the phtree header and I would have to compile a lot of source files with -fpermissive, which is undesireable.
I haven't really looked at it but it might be just a matter of some redefinitions which could be resolved with changing the naming of some internal types.
Yes, if I remember correctly it should be straight forward to do, I just haven't got around to do it yet.
I had a look on it. The problem is that you redefine types with using this way:
using Entry = Entry<DIM, T, SCALAR>;
That redefines the type Entry
which is an issue and as far as I can see, not really valid C++. If you just name the type alias with a not yet defined name, everything should be fine:
using Entry_ = Entry<DIM, T, SCALAR>;
I guess this is not your desired naming scheme, so I won't bother with a pull request yet. Unless you want me to and tell me how the naming should be done. I did some renaming and can now compile without -fpermissive
:
diff --git a/phtree/v16/debug_helper_v16.h b/phtree/v16/debug_helper_v16.h
index 12c53d9..e43bdc6 100644
--- a/phtree/v16/debug_helper_v16.h
+++ b/phtree/v16/debug_helper_v16.h
@@ -31,11 +31,11 @@ class PhTreeV16;
template <dimension_t DIM, typename T, typename SCALAR>
class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
using Key = PhPoint<DIM, SCALAR>;
- using Node = Node<DIM, T, SCALAR>;
- using Entry = Entry<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
public:
- DebugHelperV16(const Node& root, size_t size) : root_{root}, size_{size} {}
+ DebugHelperV16(const Node_& root, size_t size) : root_{root}, size_{size} {}
/*
* Depending on the detail parameter this returns:
@@ -83,9 +83,9 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
}
private:
- void ToStringPlain(std::ostringstream& os, const Node& node) const {
+ void ToStringPlain(std::ostringstream& os, const Node_& node) const {
for (auto& it : node.Entries()) {
- const Entry& o = it.second;
+ const Entry_& o = it.second;
// inner node?
if (o.IsNode()) {
ToStringPlain(os, o.GetNode());
@@ -99,7 +99,7 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
void ToStringTree(
std::ostringstream& sb,
bit_width_t current_depth,
- const Node& node,
+ const Node_& node,
const Key& prefix,
bool printValue) const {
std::string ind = "*";
@@ -142,7 +142,7 @@ class DebugHelperV16 : public PhTreeDebugHelper::DebugHelper {
}
}
- const Node& root_;
+ const Node_& root_;
const size_t size_;
};
} // namespace improbable::phtree::v16
diff --git a/phtree/v16/entry.h b/phtree/v16/entry.h
index 7546850..b425abc 100644
--- a/phtree/v16/entry.h
+++ b/phtree/v16/entry.h
@@ -41,7 +41,7 @@ template <dimension_t DIM, typename T, typename SCALAR>
class Entry {
using Key = PhPoint<DIM, SCALAR>;
using Value = std::remove_const_t<T>;
- using Node = Node<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
public:
Entry() : kd_key_(), value_{std::in_place_type<Value>, T{}} {}
@@ -49,9 +49,9 @@ class Entry {
/*
* Construct entry with existing node.
*/
- Entry(const Key& k, std::unique_ptr<Node>&& node)
+ Entry(const Key& k, std::unique_ptr<Node_>&& node)
: kd_key_{k}
- , value_{std::in_place_type<std::unique_ptr<Node>>, std::forward<std::unique_ptr<Node>>(node)} {
+ , value_{std::in_place_type<std::unique_ptr<Node_>>, std::forward<std::unique_ptr<Node_>>(node)} {
}
/*
@@ -59,8 +59,8 @@ class Entry {
*/
Entry(bit_width_t infix_len, bit_width_t postfix_len)
: kd_key_()
- , value_{std::in_place_type<std::unique_ptr<Node>>,
- std::make_unique<Node>(infix_len, postfix_len)} {}
+ , value_{std::in_place_type<std::unique_ptr<Node_>>,
+ std::make_unique<Node_>(infix_len, postfix_len)} {}
/*
* Construct entry with new T or moved T.
@@ -78,7 +78,7 @@ class Entry {
}
[[nodiscard]] bool IsNode() const {
- return std::holds_alternative<std::unique_ptr<Node>>(value_);
+ return std::holds_alternative<std::unique_ptr<Node_>>(value_);
}
[[nodiscard]] T& GetValue() const {
@@ -86,9 +86,9 @@ class Entry {
return const_cast<T&>(std::get<Value>(value_));
}
- [[nodiscard]] Node& GetNode() const {
+ [[nodiscard]] Node_& GetNode() const {
assert(IsNode());
- return *std::get<std::unique_ptr<Node>>(value_);
+ return *std::get<std::unique_ptr<Node_>>(value_);
}
void ReplaceNodeWithDataFromEntry(Entry&& other) {
@@ -98,14 +98,14 @@ class Entry {
// 'value_' points indirectly to 'entry' so we have to remove `entity's` content before
// assigning anything to `value_` here. Otherwise the assignment would destruct the previous
// content and, by reachability, `entity's` content.
- auto old_node = std::get<std::unique_ptr<Node>>(value_).release();
+ auto old_node = std::get<std::unique_ptr<Node_>>(value_).release();
value_ = std::move(other.value_);
delete old_node;
}
private:
Key kd_key_;
- std::variant<Value, std::unique_ptr<Node>> value_;
+ std::variant<Value, std::unique_ptr<Node_>> value_;
};
} // namespace improbable::phtree::v16
diff --git a/phtree/v16/for_each.h b/phtree/v16/for_each.h
index 5eb2fcb..5ac414e 100644
--- a/phtree/v16/for_each.h
+++ b/phtree/v16/for_each.h
@@ -32,20 +32,20 @@ class ForEach {
using KeyExternal = typename CONVERT::KeyExternal;
using KeyInternal = typename CONVERT::KeyInternal;
using SCALAR = typename CONVERT::ScalarInternal;
- using Entry = Entry<DIM, T, SCALAR>;
- using Node = Node<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
public:
ForEach(const CONVERT& converter, CALLBACK_FN& callback, FILTER filter)
: converter_{converter}, callback_{callback}, filter_(std::move(filter)) {}
- void run(const Entry& root) {
+ void run(const Entry_& root) {
assert(root.IsNode());
TraverseNode(root.GetKey(), root.GetNode());
}
private:
- void TraverseNode(const KeyInternal& key, const Node& node) {
+ void TraverseNode(const KeyInternal& key, const Node_& node) {
auto iter = node.Entries().begin();
auto end = node.Entries().end();
for (; iter != end; ++iter) {
diff --git a/phtree/v16/for_each_hc.h b/phtree/v16/for_each_hc.h
index dbfdefb..861b823 100644
--- a/phtree/v16/for_each_hc.h
+++ b/phtree/v16/for_each_hc.h
@@ -39,8 +39,8 @@ class ForEachHC {
using KeyExternal = typename CONVERT::KeyExternal;
using KeyInternal = typename CONVERT::KeyInternal;
using SCALAR = typename CONVERT::ScalarInternal;
- using Entry = Entry<DIM, T, SCALAR>;
- using Node = Node<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
public:
ForEachHC(
@@ -55,13 +55,13 @@ class ForEachHC {
, callback_{callback}
, filter_(std::move(filter)) {}
- void run(const Entry& root) {
+ void run(const Entry_& root) {
assert(root.IsNode());
TraverseNode(root.GetKey(), root.GetNode());
}
private:
- void TraverseNode(const KeyInternal& key, const Node& node) {
+ void TraverseNode(const KeyInternal& key, const Node_& node) {
hc_pos_t mask_lower = 0;
hc_pos_t mask_upper = 0;
CalcLimits(node.GetPostfixLen(), key, mask_lower, mask_upper);
@@ -90,7 +90,7 @@ class ForEachHC {
}
}
- bool CheckNode(const KeyInternal& key, const Node& node) const {
+ bool CheckNode(const KeyInternal& key, const Node_& node) const {
// Check if the node overlaps with the query box.
// An infix with len=0 implies that at least part of the child node overlaps with the query,
// otherwise the bit mask checking would have returned 'false'.
@@ -108,7 +108,7 @@ class ForEachHC {
return ApplyFilter(key, node);
}
- [[nodiscard]] bool ApplyFilter(const KeyInternal& key, const Node& node) const {
+ [[nodiscard]] bool ApplyFilter(const KeyInternal& key, const Node_& node) const {
return filter_.IsNodeValid(key, node.GetPostfixLen() + 1);
}
diff --git a/phtree/v16/iterator_base.h b/phtree/v16/iterator_base.h
index 8f9ae71..210754d 100644
--- a/phtree/v16/iterator_base.h
+++ b/phtree/v16/iterator_base.h
@@ -34,7 +34,7 @@ class IteratorBase {
static constexpr dimension_t DIM = CONVERT::DimInternal;
using KeyInternal = typename CONVERT::KeyInternal;
using SCALAR = typename CONVERT::ScalarInternal;
- using Entry = Entry<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
friend PhTreeV16<DIM, T, CONVERT>;
public:
@@ -96,7 +96,7 @@ class IteratorBase {
return is_finished_;
}
- const Entry* GetCurrentResult() const {
+ const Entry_* GetCurrentResult() const {
return current_result_;
}
@@ -106,22 +106,22 @@ class IteratorBase {
current_result_ = nullptr;
}
- [[nodiscard]] bool ApplyFilter(const Entry& entry) const {
+ [[nodiscard]] bool ApplyFilter(const Entry_& entry) const {
return entry.IsNode()
? filter_.IsNodeValid(entry.GetKey(), entry.GetNode().GetPostfixLen() + 1)
: filter_.IsEntryValid(entry.GetKey(), entry.GetValue());
}
- void SetCurrentResult(const Entry* current_result) {
+ void SetCurrentResult(const Entry_* current_result) {
current_result_ = current_result;
}
- void SetCurrentNodeEntry(const Entry* current_node) {
+ void SetCurrentNodeEntry(const Entry_* current_node) {
assert(!current_node || current_node->IsNode());
current_node_ = current_node;
}
- void SetParentNodeEntry(const Entry* parent_node) {
+ void SetParentNodeEntry(const Entry_* parent_node) {
assert(!parent_node || parent_node->IsNode());
parent_node_ = parent_node;
}
@@ -135,17 +135,17 @@ class IteratorBase {
* The parent entry contains the parent node. The parent node is the node ABOVE the current node
* which contains the current entry.
*/
- const Entry* GetCurrentNodeEntry() const {
+ const Entry_* GetCurrentNodeEntry() const {
return current_node_;
}
- const Entry* GetParentNodeEntry() const {
+ const Entry_* GetParentNodeEntry() const {
return parent_node_;
}
- const Entry* current_result_;
- const Entry* current_node_;
- const Entry* parent_node_;
+ const Entry_* current_result_;
+ const Entry_* current_node_;
+ const Entry_* parent_node_;
bool is_finished_;
const CONVERT& converter_;
FILTER filter_;
diff --git a/phtree/v16/iterator_full.h b/phtree/v16/iterator_full.h
index c6075f7..fa75787 100644
--- a/phtree/v16/iterator_full.h
+++ b/phtree/v16/iterator_full.h
@@ -29,7 +29,7 @@ template <typename T, typename CONVERT, typename FILTER>
class IteratorFull : public IteratorBase<T, CONVERT, FILTER> {
static constexpr dimension_t DIM = CONVERT::DimInternal;
using SCALAR = typename CONVERT::ScalarInternal;
- using Node = Node<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
using Entry = typename IteratorBase<T, CONVERT, FILTER>::Entry;
public:
@@ -73,7 +73,7 @@ class IteratorFull : public IteratorBase<T, CONVERT, FILTER> {
this->SetFinished();
}
- auto& PrepareAndPush(const Node& node) {
+ auto& PrepareAndPush(const Node_& node) {
assert(stack_size_ < stack_.size() - 1);
// No '&' because this is a temp value
stack_[stack_size_].first = node.Entries().cbegin();
diff --git a/phtree/v16/iterator_hc.h b/phtree/v16/iterator_hc.h
index 03bd655..9c31237 100644
--- a/phtree/v16/iterator_hc.h
+++ b/phtree/v16/iterator_hc.h
@@ -128,13 +128,13 @@ namespace {
template <dimension_t DIM, typename T, typename SCALAR>
class NodeIterator {
using Key = PhPoint<DIM, SCALAR>;
- using Entry = Entry<DIM, T, SCALAR>;
- using Node = Node<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
+ using Node_ = Node<DIM, T, SCALAR>;
public:
NodeIterator() : iter_{}, node_{nullptr}, mask_lower_{0}, mask_upper_(0) {}
- void init(const Key& range_min, const Key& range_max, const Node& node, const Key& prefix) {
+ void init(const Key& range_min, const Key& range_max, const Node_& node, const Key& prefix) {
node_ = &node;
CalcLimits(node.GetPostfixLen(), range_min, range_max, prefix);
iter_ = node.Entries().lower_bound(mask_lower_);
@@ -144,7 +144,7 @@ class NodeIterator {
* Advances the cursor.
* @return TRUE iff a matching element was found.
*/
- const Entry* Increment(const Key& range_min, const Key& range_max) {
+ const Entry_* Increment(const Key& range_min, const Key& range_max) {
while (iter_ != node_->Entries().end() && iter_->first <= mask_upper_) {
if (IsPosValid(iter_->first)) {
const auto* be = &iter_->second;
@@ -158,7 +158,7 @@ class NodeIterator {
return nullptr;
}
- bool CheckEntry(const Entry& candidate, const Key& range_min, const Key& range_max) const {
+ bool CheckEntry(const Entry_& candidate, const Key& range_min, const Key& range_max) const {
if (candidate.IsValue()) {
return IsInRange(candidate.GetKey(), range_min, range_max);
}
@@ -253,8 +253,8 @@ class NodeIterator {
}
private:
- EntryIteratorC<DIM, Entry> iter_;
- const Node* node_;
+ EntryIteratorC<DIM, Entry_> iter_;
+ const Node_* node_;
hc_pos_t mask_lower_;
hc_pos_t mask_upper_;
};
diff --git a/phtree/v16/iterator_knn_hs.h b/phtree/v16/iterator_knn_hs.h
index 30a1dd6..2bd401a 100644
--- a/phtree/v16/iterator_knn_hs.h
+++ b/phtree/v16/iterator_knn_hs.h
@@ -50,7 +50,7 @@ class IteratorKnnHS : public IteratorBase<T, CONVERT, FILTER> {
using KeyInternal = typename CONVERT::KeyInternal;
using SCALAR = typename CONVERT::ScalarInternal;
using Entry = typename IteratorBase<T, CONVERT, FILTER>::Entry;
- using EntryDist = EntryDist<DIM, T, SCALAR>;
+ using EntryDist_ = EntryDist<DIM, T, SCALAR>;
public:
explicit IteratorKnnHS(
@@ -152,7 +152,7 @@ class IteratorKnnHS : public IteratorBase<T, CONVERT, FILTER> {
// center after post processing == the external representation
const KeyExternal center_post_;
double current_distance_;
- std::priority_queue<EntryDist, std::vector<EntryDist>, CompareEntryDistByDistance<EntryDist>>
+ std::priority_queue<EntryDist_, std::vector<EntryDist_>, CompareEntryDistByDistance<EntryDist_>>
queue_;
int num_found_results_;
int num_requested_results_;
diff --git a/phtree/v16/node.h b/phtree/v16/node.h
index 7f550c5..0285ab4 100644
--- a/phtree/v16/node.h
+++ b/phtree/v16/node.h
@@ -109,7 +109,7 @@ void MergeIntoParent(Node<DIM, T, SCALAR>& child_node, Node<DIM, T, SCALAR>& par
template <dimension_t DIM, typename T, typename SCALAR>
class Node {
using Key = PhPoint<DIM, SCALAR>;
- using Entry = Entry<DIM, T, SCALAR>;
+ using Entry_ = Entry<DIM, T, SCALAR>;
public:
Node(bit_width_t infix_len, bit_width_t postfix_len)
@@ -164,7 +164,7 @@ class Node {
* @param __args Constructor arguments for creating a value T that can be inserted for the key.
*/
template <typename... _Args>
- Entry* Emplace(bool& is_inserted, const Key& key, _Args&&... __args) {
+ Entry_* Emplace(bool& is_inserted, const Key& key, _Args&&... __args) {
hc_pos_t hc_pos = CalcPosInArray(key, GetPostfixLen());
auto emplace_result = entries_.try_emplace(hc_pos, key, std::forward<_Args>(__args)...);
auto& entry = emplace_result.first->second;
@@ -183,7 +183,7 @@ class Node {
* @param parent parent node
* @return The sub node or null.
*/
- const Entry* Find(const Key& key) const {
+ const Entry_* Find(const Key& key) const {
hc_pos_t hc_pos = CalcPosInArray(key, GetPostfixLen());
const auto& entry = entries_.find(hc_pos);
if (entry != entries_.end() && DoesEntryMatch(entry->second, key)) {
@@ -285,7 +285,7 @@ class Node {
return entries_.try_emplace(hc_pos, new_key, std::forward<_Args>(__args)...).first->second;
}
- void WriteEntry(hc_pos_t hc_pos, Entry&& entry) {
+ void WriteEntry(hc_pos_t hc_pos, Entry_&& entry) {
if (entry.IsNode()) {
auto& node = entry.GetNode();
bit_width_t new_subnode_infix_len = postfix_len_ - node.postfix_len_ - 1;
@@ -310,7 +310,7 @@ class Node {
*/
template <typename... _Args>
auto* HandleCollision(
- Entry& existing_entry, bool& is_inserted, const Key& new_key, _Args&&... __args) {
+ Entry_& existing_entry, bool& is_inserted, const Key& new_key, _Args&&... __args) {
assert(!is_inserted);
// We have two entries in the same location (local pos).
// Now we need to compare the keys.
@@ -345,7 +345,7 @@ class Node {
template <typename... _Args>
auto* InsertSplit(
- Entry& current_entry,
+ Entry_& current_entry,
const Key& new_key,
bit_width_t max_conflicting_bits,
_Args&&... __args) {
@@ -378,7 +378,7 @@ class Node {
* @return 'true' iff the relevant part of the key matches (prefix for nodes, whole key for
* other entries).
*/
- bool DoesEntryMatch(const Entry& entry, const Key& key) const {
+ bool DoesEntryMatch(const Entry_& entry, const Key& key) const {
if (entry.IsNode()) {
const auto& sub = entry.GetNode();
if (sub.GetInfixLen() > 0) {
@@ -400,7 +400,7 @@ class Node {
// The number of bits between this node and the parent node. For 64bit keys possible values
// range from 0 to 62.
bit_width_t infix_len_;
- EntryMap<DIM, Entry> entries_;
+ EntryMap<DIM, Entry_> entries_;
};
} // namespace improbable::phtree::v16
diff --git a/phtree/v16/phtree_v16.h b/phtree/v16/phtree_v16.h
index a09351f..0036a47 100644
--- a/phtree/v16/phtree_v16.h
+++ b/phtree/v16/phtree_v16.h
@@ -57,8 +57,8 @@ class PhTreeV16 {
using ScalarExternal = typename CONVERT::ScalarExternal;
using ScalarInternal = typename CONVERT::ScalarInternal;
using Key = typename CONVERT::KeyInternal;
- using Node = Node<DIM, T, ScalarInternal>;
- using Entry = Entry<DIM, T, ScalarInternal>;
+ using Node_ = Node<DIM, T, ScalarInternal>;
+ using Entry_ = Entry<DIM, T, ScalarInternal>;
public:
static_assert(!std::is_reference<T>::value, "Reference type value are not supported.");
@@ -198,9 +198,9 @@ class PhTreeV16 {
return IteratorSimple<T, CONVERT>(converter_);
}
- const Entry* current_entry = &root_;
- const Entry* current_node = nullptr;
- const Entry* parent_node = nullptr;
+ const Entry_* current_entry = &root_;
+ const Entry_* current_node = nullptr;
+ const Entry_* parent_node = nullptr;
while (current_entry && current_entry->IsNode()) {
parent_node = current_node;
current_node = current_entry;
@@ -217,7 +217,7 @@ class PhTreeV16 {
*/
size_t erase(const Key& key) {
auto* current_node = &root_.GetNode();
- Node* parent_node = nullptr;
+ Node_* parent_node = nullptr;
bool found = false;
while (current_node) {
auto* child_node = current_node->Erase(key, parent_node, found);
@@ -362,7 +362,7 @@ class PhTreeV16 {
*/
void clear() {
num_entries_ = 0;
- root_ = Entry(0, MAX_BIT_WIDTH<ScalarInternal> - 1);
+ root_ = Entry_(0, MAX_BIT_WIDTH<ScalarInternal> - 1);
}
/*
@@ -391,7 +391,7 @@ class PhTreeV16 {
size_t num_entries_;
// Contract: root_ contains a Node with 0 or more entries (the root node is the only Node
// that is allowed to have less than two entries.
- Entry root_;
+ Entry_ root_;
IteratorEnd<T, CONVERT> the_end_;
CONVERT converter_;
};
Hi @aurelw, thanks for looking into this. I just released a fix: https://github.com/improbable-eng/phtree-cpp/pull/11 It now compiles on gcc -Wall -Werror
I try to create a minimal example and included phtree.h:
However, I get the following compile errors.... just the first lines of the compiler output:
..... and so on.
I compile with gcc and
CMAKE_CXX_STANDARD 17
. When I compile the library withExample
, everything works fine though. What am I missing here?