File: robust_against_poison_pills.compile.pass.cpp

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (102 lines) | stat: -rw-r--r-- 5,706 bytes parent folder | download | duplicates (9)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <compare>, <iterator>, <ranges>

// ADL should be performed. Ordinary unqualified lookup should not be performed.

namespace ns {
struct StructWithGlobalFunctions {};
} // namespace ns

struct ConvertibleToCmpType;
ConvertibleToCmpType strong_order(const ns::StructWithGlobalFunctions&, const ns::StructWithGlobalFunctions&);
ConvertibleToCmpType weak_order(const ns::StructWithGlobalFunctions&, const ns::StructWithGlobalFunctions&);
ConvertibleToCmpType partial_order(const ns::StructWithGlobalFunctions&, const ns::StructWithGlobalFunctions&);

int&& iter_move(const ns::StructWithGlobalFunctions&);
void iter_swap(const ns::StructWithGlobalFunctions&, const ns::StructWithGlobalFunctions&);

int* begin(const ns::StructWithGlobalFunctions&);
int* end(const ns::StructWithGlobalFunctions&);
int* rbegin(const ns::StructWithGlobalFunctions&);
int* rend(const ns::StructWithGlobalFunctions&);
unsigned int size(const ns::StructWithGlobalFunctions&);

#include <compare>
#include <ranges>
#include <type_traits>

struct ConvertibleToCmpType {
  operator std::strong_ordering() const;
  operator std::weak_ordering() const;
  operator std::partial_ordering() const;
};

struct StructWithHiddenFriends {
  friend ConvertibleToCmpType strong_order(const StructWithHiddenFriends&, const StructWithHiddenFriends&);
  friend ConvertibleToCmpType weak_order(const StructWithHiddenFriends&, const StructWithHiddenFriends&);
  friend ConvertibleToCmpType partial_order(const StructWithHiddenFriends&, const StructWithHiddenFriends&);

  friend int&& iter_move(const StructWithHiddenFriends&);
  friend void iter_swap(const StructWithHiddenFriends&, const StructWithHiddenFriends&);

  friend int* begin(const StructWithHiddenFriends&);
  friend int* end(const StructWithHiddenFriends&);
  friend int* rbegin(const StructWithHiddenFriends&);
  friend int* rend(const StructWithHiddenFriends&);
  friend unsigned int size(const StructWithHiddenFriends&);
};

// [cmp.alg] ADL should be performed.
static_assert(std::is_invocable_v<decltype(std::strong_order), StructWithHiddenFriends&, StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::weak_order), StructWithHiddenFriends&, StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::partial_order), StructWithHiddenFriends&, StructWithHiddenFriends&>);

// [cmp.alg] Ordinary unqualified lookup should not be performed.
static_assert(
    !std::is_invocable_v<decltype(std::strong_order), ns::StructWithGlobalFunctions&, ns::StructWithGlobalFunctions&>);
static_assert(
    !std::is_invocable_v<decltype(std::weak_order), ns::StructWithGlobalFunctions&, ns::StructWithGlobalFunctions&>);
static_assert(
    !std::is_invocable_v<decltype(std::partial_order), ns::StructWithGlobalFunctions&, ns::StructWithGlobalFunctions&>);

// [iterator.cust] ADL should be performed.
static_assert(std::is_invocable_v<decltype(std::ranges::iter_move), StructWithHiddenFriends&>);
static_assert(
    std::is_invocable_v<decltype(std::ranges::iter_swap), StructWithHiddenFriends&, StructWithHiddenFriends&>);

// [iterator.cust] Ordinary unqualified lookup should not be performed.
static_assert(!std::is_invocable_v<decltype(std::ranges::iter_move), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::iter_swap),
                                   ns::StructWithGlobalFunctions&,
                                   ns::StructWithGlobalFunctions&>);

// [range.access] ADL should be performed.
static_assert(std::is_invocable_v<decltype(std::ranges::begin), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::cbegin), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::end), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::cend), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::rbegin), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::crbegin), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::rend), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::crend), StructWithHiddenFriends&>);
static_assert(std::is_invocable_v<decltype(std::ranges::size), StructWithHiddenFriends&>);

// [range.access] Ordinary unqualified lookup should not be performed.
static_assert(!std::is_invocable_v<decltype(std::ranges::begin), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::cbegin), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::end), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::cend), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::rbegin), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::crbegin), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::rend), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::crend), ns::StructWithGlobalFunctions&>);
static_assert(!std::is_invocable_v<decltype(std::ranges::size), ns::StructWithGlobalFunctions&>);