12561885fSEric Fiselier //===----------------------------------------------------------------------===//
22561885fSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62561885fSEric Fiselier //
72561885fSEric Fiselier //===----------------------------------------------------------------------===//
82561885fSEric Fiselier 
92561885fSEric Fiselier // <memory>
102561885fSEric Fiselier 
112561885fSEric Fiselier // unique_ptr
122561885fSEric Fiselier 
132561885fSEric Fiselier // test op[](size_t)
142561885fSEric Fiselier 
152561885fSEric Fiselier #include <memory>
162561885fSEric Fiselier #include <cassert>
172561885fSEric Fiselier 
18*7fc6a556SMarshall Clow #include "test_macros.h"
19*7fc6a556SMarshall Clow 
202561885fSEric Fiselier class A {
212561885fSEric Fiselier   int state_;
222561885fSEric Fiselier   static int next_;
232561885fSEric Fiselier 
242561885fSEric Fiselier public:
A()252561885fSEric Fiselier   A() : state_(++next_) {}
get() const262561885fSEric Fiselier   int get() const { return state_; }
272561885fSEric Fiselier 
operator ==(const A & x,int y)282561885fSEric Fiselier   friend bool operator==(const A& x, int y) { return x.state_ == y; }
292561885fSEric Fiselier 
operator =(int i)302561885fSEric Fiselier   A& operator=(int i) {
312561885fSEric Fiselier     state_ = i;
322561885fSEric Fiselier     return *this;
332561885fSEric Fiselier   }
342561885fSEric Fiselier };
352561885fSEric Fiselier 
362561885fSEric Fiselier int A::next_ = 0;
372561885fSEric Fiselier 
main(int,char **)382df59c50SJF Bastien int main(int, char**) {
392561885fSEric Fiselier   std::unique_ptr<A[]> p(new A[3]);
402561885fSEric Fiselier   assert(p[0] == 1);
412561885fSEric Fiselier   assert(p[1] == 2);
422561885fSEric Fiselier   assert(p[2] == 3);
432561885fSEric Fiselier   p[0] = 3;
442561885fSEric Fiselier   p[1] = 2;
452561885fSEric Fiselier   p[2] = 1;
462561885fSEric Fiselier   assert(p[0] == 3);
472561885fSEric Fiselier   assert(p[1] == 2);
482561885fSEric Fiselier   assert(p[2] == 1);
492df59c50SJF Bastien 
502df59c50SJF Bastien   return 0;
512561885fSEric Fiselier }
52