Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / from_range_deduction.pass.cpp
blobb2dab03506f03a46cef6a5929ade9402b0f184d7
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: -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"
30 int main(int, char**) {
31 using Char = char16_t;
34 std::basic_string c(std::from_range, std::array<Char, 0>());
35 static_assert(std::is_same_v<decltype(c), std::basic_string<Char>>);
39 using Alloc = test_allocator<Char>;
40 std::basic_string c(std::from_range, std::array<Char, 0>(), Alloc());
41 static_assert(std::is_same_v<decltype(c), std::basic_string<Char, std::char_traits<Char>, Alloc>>);
44 // Note: defining `value_type` is a workaround because one of the deduction guides will end up instantiating
45 // `basic_string`, and that would fail with a hard error if the given allocator doesn't define `value_type`.
46 struct BadAlloc {
47 using value_type = char;
49 SequenceContainerDeductionGuidesSfinaeAway<std::basic_string, std::basic_string<char>, BadAlloc>();
51 return 0;