[libc][NFC] Remove extra ; in exhaustive_test.h. (#124216)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / from_range_deduction.pass.cpp
blob44aa0980972bd1e05726f1d9bc75624713f80a53
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
12 // To silence a GCC warning-turned-error re. `BadAlloc::value_type`.
13 // ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-unused-local-typedefs
15 // template<ranges::input_range R,
16 // class Allocator = allocator<ranges::range_value_t<R>>>
17 // basic_string(from_range_t, R&&, Allocator = Allocator())
18 // -> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>,
19 // Allocator>; // C++23
21 // The deduction guide shall not participate in overload resolution if Allocator
22 // is a type that does not qualify as an allocator (in addition to the `input_range` concept being satisfied by `R`).
24 #include <array>
25 #include <string>
27 #include "deduction_guides_sfinae_checks.h"
28 #include "test_allocator.h"
29 #include "asan_testing.h"
31 int main(int, char**) {
32 using Char = char16_t;
35 std::basic_string c(std::from_range, std::array<Char, 0>());
36 static_assert(std::is_same_v<decltype(c), std::basic_string<Char>>);
37 LIBCPP_ASSERT(is_string_asan_correct(c));
41 using Alloc = test_allocator<Char>;
42 std::basic_string c(std::from_range, std::array<Char, 0>(), Alloc());
43 static_assert(std::is_same_v<decltype(c), std::basic_string<Char, std::char_traits<Char>, Alloc>>);
44 LIBCPP_ASSERT(is_string_asan_correct(c));
47 // Note: defining `value_type` is a workaround because one of the deduction guides will end up instantiating
48 // `basic_string`, and that would fail with a hard error if the given allocator doesn't define `value_type`.
49 struct BadAlloc {
50 using value_type = char;
52 SequenceContainerDeductionGuidesSfinaeAway<std::basic_string, std::basic_string<char>, BadAlloc>();
54 return 0;