1baf6f918Svarconst //===----------------------------------------------------------------------===//
2baf6f918Svarconst //
3baf6f918Svarconst // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4baf6f918Svarconst // See https://llvm.org/LICENSE.txt for license information.
5baf6f918Svarconst // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6baf6f918Svarconst //
7baf6f918Svarconst //===----------------------------------------------------------------------===//
8baf6f918Svarconst
9baf6f918Svarconst // <string>
10baf6f918Svarconst
11baf6f918Svarconst // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
12baf6f918Svarconst // To silence a GCC warning-turned-error re. `BadAlloc::value_type`.
13*64addd65SStephan T. Lavavej // ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-unused-local-typedefs
14baf6f918Svarconst
15baf6f918Svarconst // template<ranges::input_range R,
16baf6f918Svarconst // class Allocator = allocator<ranges::range_value_t<R>>>
17baf6f918Svarconst // basic_string(from_range_t, R&&, Allocator = Allocator())
18baf6f918Svarconst // -> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>,
19baf6f918Svarconst // Allocator>; // C++23
20baf6f918Svarconst //
21baf6f918Svarconst // The deduction guide shall not participate in overload resolution if Allocator
22baf6f918Svarconst // is a type that does not qualify as an allocator (in addition to the `input_range` concept being satisfied by `R`).
23baf6f918Svarconst
24baf6f918Svarconst #include <array>
25baf6f918Svarconst #include <string>
26baf6f918Svarconst
27baf6f918Svarconst #include "deduction_guides_sfinae_checks.h"
28baf6f918Svarconst #include "test_allocator.h"
299ed20568STacet #include "asan_testing.h"
30baf6f918Svarconst
main(int,char **)31baf6f918Svarconst int main(int, char**) {
32baf6f918Svarconst using Char = char16_t;
33baf6f918Svarconst
34baf6f918Svarconst {
35baf6f918Svarconst std::basic_string c(std::from_range, std::array<Char, 0>());
36baf6f918Svarconst static_assert(std::is_same_v<decltype(c), std::basic_string<Char>>);
379ed20568STacet LIBCPP_ASSERT(is_string_asan_correct(c));
38baf6f918Svarconst }
39baf6f918Svarconst
40baf6f918Svarconst {
41baf6f918Svarconst using Alloc = test_allocator<Char>;
42baf6f918Svarconst std::basic_string c(std::from_range, std::array<Char, 0>(), Alloc());
43baf6f918Svarconst static_assert(std::is_same_v<decltype(c), std::basic_string<Char, std::char_traits<Char>, Alloc>>);
449ed20568STacet LIBCPP_ASSERT(is_string_asan_correct(c));
45baf6f918Svarconst }
46baf6f918Svarconst
47baf6f918Svarconst // Note: defining `value_type` is a workaround because one of the deduction guides will end up instantiating
48baf6f918Svarconst // `basic_string`, and that would fail with a hard error if the given allocator doesn't define `value_type`.
49a40bada9SBrendan Emery struct BadAlloc {
50a40bada9SBrendan Emery using value_type = char;
51a40bada9SBrendan Emery };
52baf6f918Svarconst SequenceContainerDeductionGuidesSfinaeAway<std::basic_string, std::basic_string<char>, BadAlloc>();
53baf6f918Svarconst
54baf6f918Svarconst return 0;
55baf6f918Svarconst }
56