brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 50c4f5d Raw
91 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <vector>10 11// pointer data();12 13#include <vector>14#include <cassert>15 16#include "test_macros.h"17#include "min_allocator.h"18#include "asan_testing.h"19 20struct Nasty {21  TEST_CONSTEXPR Nasty() : i_(0) {}22  TEST_CONSTEXPR Nasty(int i) : i_(i) {}23  TEST_CONSTEXPR_CXX20 ~Nasty() {}24 25  Nasty* operator&() const {26    assert(false);27    return nullptr;28  }29  int i_;30};31 32TEST_CONSTEXPR_CXX20 bool tests() {33  {34    std::vector<int> v;35    assert(v.data() == 0);36    assert(is_contiguous_container_asan_correct(v));37  }38  {39    std::vector<int> v(100);40    assert(v.data() == std::addressof(v.front()));41    assert(is_contiguous_container_asan_correct(v));42  }43  {44    std::vector<Nasty> v(100);45    assert(v.data() == std::addressof(v.front()));46    assert(is_contiguous_container_asan_correct(v));47  }48#if TEST_STD_VER >= 1149  {50    std::vector<int, min_allocator<int>> v;51    assert(v.data() == 0);52    assert(is_contiguous_container_asan_correct(v));53  }54  {55    std::vector<int, min_allocator<int>> v(100);56    assert(v.data() == std::addressof(v.front()));57    assert(is_contiguous_container_asan_correct(v));58  }59  {60    std::vector<Nasty, min_allocator<Nasty>> v(100);61    assert(v.data() == std::addressof(v.front()));62    assert(is_contiguous_container_asan_correct(v));63  }64  {65    std::vector<int, safe_allocator<int>> v;66    assert(v.data() == 0);67    assert(is_contiguous_container_asan_correct(v));68  }69  {70    std::vector<int, safe_allocator<int>> v(100);71    assert(v.data() == std::addressof(v.front()));72    assert(is_contiguous_container_asan_correct(v));73  }74  {75    std::vector<Nasty, safe_allocator<Nasty>> v(100);76    assert(v.data() == std::addressof(v.front()));77    assert(is_contiguous_container_asan_correct(v));78  }79#endif80 81  return true;82}83 84int main(int, char**) {85  tests();86#if TEST_STD_VER > 1787  static_assert(tests());88#endif89  return 0;90}91