From 783b372a580c59bb3aae3b37f32df17b3a2b3928 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 10 May 2015 13:14:08 +0000 Subject: Fix for LWG2454: Add raw_storage_iterator::base() member llvm-svn: 236948 --- .../raw_storag_iterator.base.pass.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 libcxx/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp (limited to 'libcxx/test/std/utilities') diff --git a/libcxx/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp b/libcxx/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp new file mode 100644 index 00000000000..27b620569b8 --- /dev/null +++ b/libcxx/test/std/utilities/memory/storage.iterator/raw_storag_iterator.base.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// raw_storage_iterator + +#include +#include +#include + +int A_constructed = 0; + +struct A +{ + int data_; +public: + explicit A(int i) : data_(i) {++A_constructed;} + + A(const A& a) : data_(a.data_) {++A_constructed;} + ~A() {--A_constructed; data_ = 0;} + + bool operator==(int i) const {return data_ == i;} +}; + +int main() +{ +#if __cplusplus >= 201402L + typedef std::aligned_storage<3*sizeof(A), std::alignment_of::value>::type + Storage; + Storage buffer; + std::raw_storage_iterator it((A*)&buffer); + assert(A_constructed == 0); + assert(it.base() == (A*)&buffer); + for (int i = 0; i < 3; ++i) + { + *it++ = A(i+1); + A* ap = (A*)&buffer + i; + assert(*ap == i+1); + assert(A_constructed == i+1); + assert(it.base() == ap + 1); // next place to write + } +#endif +} -- cgit v1.2.3