[llvm] 0165e33 - [llvm][Object] Add missing const qualifier for value_type in content_iterator (#124106)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 28 02:22:51 PST 2025
Author: Bushev Dmitry
Date: 2025-01-28T13:22:48+03:00
New Revision: 0165e3346fdb1a3f51352821227d6ff1af5aee59
URL: https://github.com/llvm/llvm-project/commit/0165e3346fdb1a3f51352821227d6ff1af5aee59
DIFF: https://github.com/llvm/llvm-project/commit/0165e3346fdb1a3f51352821227d6ff1af5aee59.diff
LOG: [llvm][Object] Add missing const qualifier for value_type in content_iterator (#124106)
value_type was defined as non-const for content_iterator, although it's
methods returned a const pointers/references. This prevented it from
using in some algorithms from STLExtras.h
Added:
Modified:
llvm/include/llvm/Object/SymbolicFile.h
llvm/unittests/Object/SymbolicFileTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/SymbolicFile.h b/llvm/include/llvm/Object/SymbolicFile.h
index b13588c147d9b2..2c857e72c3e5a6 100644
--- a/llvm/include/llvm/Object/SymbolicFile.h
+++ b/llvm/include/llvm/Object/SymbolicFile.h
@@ -71,7 +71,7 @@ template <class content_type> class content_iterator {
public:
using iterator_category = std::forward_iterator_tag;
- using value_type = content_type;
+ using value_type = const content_type;
using
diff erence_type = std::ptr
diff _t;
using pointer = value_type *;
using reference = value_type &;
diff --git a/llvm/unittests/Object/SymbolicFileTest.cpp b/llvm/unittests/Object/SymbolicFileTest.cpp
index 38875ce7b8cd99..c3813b12b4476d 100644
--- a/llvm/unittests/Object/SymbolicFileTest.cpp
+++ b/llvm/unittests/Object/SymbolicFileTest.cpp
@@ -7,8 +7,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/SymbolicFile.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <sstream>
@@ -38,3 +40,22 @@ TEST(Object, DataRefImplOstream) {
EXPECT_EQ(Expected, s);
}
+
+struct ProxyContent {
+ unsigned Index = 0;
+ ProxyContent(unsigned Index) : Index(Index) {};
+ void moveNext() { ++Index; }
+
+ bool operator==(const ProxyContent &Another) const {
+ return Index == Another.Index;
+ }
+};
+
+TEST(Object, ContentIterator) {
+ using Iter = llvm::object::content_iterator<ProxyContent>;
+ auto Sequence = llvm::make_range(Iter(0u), Iter(10u));
+ auto EvenSequence = llvm::make_filter_range(
+ Sequence, [](auto &&PC) { return PC.Index % 2 == 0; });
+
+ EXPECT_THAT(EvenSequence, testing::ElementsAre(0u, 2u, 4u, 6u, 8u));
+}
More information about the llvm-commits
mailing list