brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 77da292 Raw
38 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// <string>10 11#include <algorithm>12#include <cassert>13#include <cstddef>14#include <string>15 16#include "test_macros.h"17 18// alignment of the string heap buffer is hardcoded to 819const std::size_t alignment = 8;20 21int main(int, char**) {22  std::string input_string;23  input_string.resize(64, 'a');24 25  // Call a constructor which selects its size using __recommend.26  std::string test_string(input_string.data());27  const std::size_t expected_align8_size = 71;28 29  // Demonstrate the lesser capacity/allocation size when the alignment requirement is 8.30  if (alignment == 8) {31    assert(test_string.capacity() == expected_align8_size);32  } else {33    assert(test_string.capacity() == expected_align8_size + 8);34  }35 36  return 0;37}38