summaryrefslogtreecommitdiff
path: root/libcxx/test/std/strings/basic.string/string.capacity/resize_and_overwrite.verify.cpp
blob: 323f49b72c2c845cb8feae626e2cbd00629190cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++23

// <string>

// template<class Operation>
// void resize_and_overwrite(size_type n, Operation op)

// Verify that the operation's return type must be integer-like

#include <string>

void test_bool_return_type() {
  std::string s;
  s.resize_and_overwrite(10, [](char*, std::size_t) {
    return true; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}}
  });
}

void test_pointer_return_type() {
  std::string s;
  s.resize_and_overwrite(10, [](char* p, std::size_t) {
    return p; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}}
              // expected-error@*:* {{cannot initialize}}
  });
}

void test_float_return_type() {
  std::string s;
  s.resize_and_overwrite(10, [](char*, std::size_t) {
    return 5.0f; // expected-error-re@*:* {{{{(static_assertion|static assertion)}}{{.*}}integer-like}}
  });
}