llvm/unittests/ADT/ReverseIterationTest.cpp
Abhilash Bhandari 8e487760c5 [ADT] Fix for compilation error when operator++(int) (post-increment function) of SmallPtrSetIterator is used.
The bug was introduced in r289619.

Reviewers: Mehdi Amini

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D28134

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290749 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-30 12:34:36 +00:00

53 lines
1.6 KiB
C++

//===- llvm/unittest/ADT/ReverseIterationTest.cpp ------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// ReverseIteration unit tests.
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "llvm/ADT/SmallPtrSet.h"
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
using namespace llvm;
TEST(ReverseIterationTest, SmallPtrSetTest) {
SmallPtrSet<void*, 4> Set;
void *Ptrs[] = { (void*)0x1, (void*)0x2, (void*)0x3, (void*)0x4 };
void *ReversePtrs[] = { (void*)0x4, (void*)0x3, (void*)0x2, (void*)0x1 };
for (auto *Ptr: Ptrs)
Set.insert(Ptr);
// Check forward iteration.
ReverseIterate<bool>::value = false;
for (const auto &Tuple : zip(Set, Ptrs))
ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
// Check operator++ (post-increment) in forward iteration.
int i = 0;
for (auto begin = Set.begin(), end = Set.end();
begin != end; i++)
ASSERT_EQ(*begin++, Ptrs[i]);
// Check reverse iteration.
ReverseIterate<bool>::value = true;
for (const auto &Tuple : zip(Set, ReversePtrs))
ASSERT_EQ(std::get<0>(Tuple), std::get<1>(Tuple));
// Check operator++ (post-increment) in reverse iteration.
i = 0;
for (auto begin = Set.begin(), end = Set.end();
begin != end; i++)
ASSERT_EQ(*begin++, ReversePtrs[i]);
}
#endif