Skip to content

Commit 0165e33

Browse files
authored
[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
1 parent 7cd6f85 commit 0165e33

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

llvm/include/llvm/Object/SymbolicFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ template <class content_type> class content_iterator {
7171

7272
public:
7373
using iterator_category = std::forward_iterator_tag;
74-
using value_type = content_type;
74+
using value_type = const content_type;
7575
using difference_type = std::ptrdiff_t;
7676
using pointer = value_type *;
7777
using reference = value_type &;

llvm/unittests/Object/SymbolicFileTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Object/SymbolicFile.h"
10+
#include "llvm/ADT/STLExtras.h"
1011
#include "llvm/Support/raw_ostream.h"
1112
#include "llvm/TargetParser/Host.h"
13+
#include "gmock/gmock.h"
1214
#include "gtest/gtest.h"
1315
#include <sstream>
1416

@@ -38,3 +40,22 @@ TEST(Object, DataRefImplOstream) {
3840

3941
EXPECT_EQ(Expected, s);
4042
}
43+
44+
struct ProxyContent {
45+
unsigned Index = 0;
46+
ProxyContent(unsigned Index) : Index(Index) {};
47+
void moveNext() { ++Index; }
48+
49+
bool operator==(const ProxyContent &Another) const {
50+
return Index == Another.Index;
51+
}
52+
};
53+
54+
TEST(Object, ContentIterator) {
55+
using Iter = llvm::object::content_iterator<ProxyContent>;
56+
auto Sequence = llvm::make_range(Iter(0u), Iter(10u));
57+
auto EvenSequence = llvm::make_filter_range(
58+
Sequence, [](auto &&PC) { return PC.Index % 2 == 0; });
59+
60+
EXPECT_THAT(EvenSequence, testing::ElementsAre(0u, 2u, 4u, 6u, 8u));
61+
}

0 commit comments

Comments
 (0)