Skip to content

Fix getParent / getNodeBaseParent to return pointer to const (#94224) #96053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/include/llvm/ADT/ilist_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "llvm/ADT/ilist_node_base.h"
#include "llvm/ADT/ilist_node_options.h"
#include <type_traits>

namespace llvm {

Expand All @@ -29,7 +30,9 @@ struct NodeAccess;
/// has been set in the list options.
template <class NodeTy, class ParentPtrTy> class node_parent_access {
public:
inline const ParentPtrTy getParent() const {
using ConstParentPtrTy =
std::add_pointer_t<std::add_const_t<std::remove_pointer_t<ParentPtrTy>>>;
inline ConstParentPtrTy getParent() const {
return static_cast<const NodeTy *>(this)->getNodeBaseParent();
}
inline ParentPtrTy getParent() {
Expand Down
5 changes: 4 additions & 1 deletion llvm/include/llvm/ADT/ilist_node_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_ADT_ILIST_NODE_BASE_H

#include "llvm/ADT/PointerIntPair.h"
#include <type_traits>

namespace llvm {

Expand Down Expand Up @@ -48,10 +49,12 @@ template <class NodeBase> class node_base_prevnext<NodeBase, true> {

template <class ParentPtrTy> class node_base_parent {
ParentPtrTy Parent = nullptr;
using ConstParentPtrTy =
std::add_pointer_t<std::add_const_t<std::remove_pointer_t<ParentPtrTy>>>;

public:
void setNodeBaseParent(ParentPtrTy Parent) { this->Parent = Parent; }
inline const ParentPtrTy getNodeBaseParent() const { return Parent; }
inline ConstParentPtrTy getNodeBaseParent() const { return Parent; }
inline ParentPtrTy getNodeBaseParent() { return Parent; }
};
template <> class node_base_parent<void> {};
Expand Down
Loading