| 1 |
// { dg-options "-g -O0 -std=gnu++2a" } |
| 2 |
// { dg-do run { target c++2a } } |
| 3 |
|
| 4 |
// Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 5 |
// |
| 6 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 7 |
// software; you can redistribute it and/or modify it under the |
| 8 |
// terms of the GNU General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3, or (at your option) |
| 10 |
// any later version. |
| 11 |
|
| 12 |
// This library is distributed in the hope that it will be useful, |
| 13 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
// GNU General Public License for more details. |
| 16 |
|
| 17 |
// You should have received a copy of the GNU General Public License along |
| 18 |
// with this library; see the file COPYING3. If not see |
| 19 |
// <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
#include <array> |
| 22 |
#include <compare> |
| 23 |
#include <iostream> |
| 24 |
#include <memory> |
| 25 |
#include <span> |
| 26 |
|
| 27 |
struct X |
| 28 |
{ |
| 29 |
int i; |
| 30 |
|
| 31 |
std::weak_ordering operator<=>(X x) const noexcept { return i <=> x.i; } |
| 32 |
}; |
| 33 |
|
| 34 |
int |
| 35 |
main() |
| 36 |
{ |
| 37 |
auto c1 = 1 <=> 1; |
| 38 |
// { dg-final { note-test c1 "std::strong_ordering::equal" } } |
| 39 |
auto c2 = 1 <=> 2; |
| 40 |
// { dg-final { note-test c2 "std::strong_ordering::less" } } |
| 41 |
auto c3 = 4 <=> 3; |
| 42 |
// { dg-final { note-test c3 "std::strong_ordering::greater" } } |
| 43 |
|
| 44 |
auto c4 = X{1} <=> X{1}; |
| 45 |
// { dg-final { note-test c4 "std::weak_ordering::equivalent" } } |
| 46 |
auto c5 = X{2} <=> X{3}; |
| 47 |
// { dg-final { note-test c5 "std::weak_ordering::less" } } |
| 48 |
auto c6 = X{2} <=> X{1}; |
| 49 |
// { dg-final { note-test c6 "std::weak_ordering::greater" } } |
| 50 |
|
| 51 |
auto c7 = 0.2 <=> 0.2; |
| 52 |
// { dg-final { note-test c7 "std::partial_ordering::equivalent" } } |
| 53 |
auto c8 = 2.5 <=> 5.5; |
| 54 |
// { dg-final { note-test c8 "std::partial_ordering::less" } } |
| 55 |
auto c9 = 7.5 <=> -2.2; |
| 56 |
// { dg-final { note-test c9 "std::partial_ordering::greater" } } |
| 57 |
auto c10 = 0.0 <=> __builtin_nan(""); |
| 58 |
// { dg-final { note-test c10 "std::partial_ordering::unordered" } } |
| 59 |
|
| 60 |
auto il = {1, 2}; |
| 61 |
auto s1 = std::span(il); |
| 62 |
static_assert(s1.extent == std::size_t(-1)); |
| 63 |
// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } } |
| 64 |
auto a = std::array{3, 4}; |
| 65 |
auto s2 = std::span(a); |
| 66 |
static_assert(s2.extent == std::size_t(2)); |
| 67 |
// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } } |
| 68 |
|
| 69 |
std::atomic<std::shared_ptr<int>> spe; |
| 70 |
// { dg-final { note-test spe {std::atomic<std::shared_ptr<int>> (empty) = {get() = 0x0}} } } |
| 71 |
std::atomic<std::shared_ptr<int>> sp1 = std::make_shared<int>(1); |
| 72 |
std::atomic<std::shared_ptr<int>> sp2 = sp1.load(); |
| 73 |
std::atomic<std::weak_ptr<int>> wp{sp2.load()}; |
| 74 |
// { dg-final { regexp-test sp1 {std::atomic.std::shared_ptr.int.. \(use count 2, weak count 1\) = {get\(\) = 0x.*}} } } |
| 75 |
// { dg-final { regexp-test wp {std::atomic.std::weak_ptr.int.. \(use count 2, weak count 1\) = {get\(\) = 0x.*}} } } |
| 76 |
|
| 77 |
std::cout << "\n"; |
| 78 |
return 0; // Mark SPOT |
| 79 |
} |
| 80 |
|
| 81 |
// { dg-final { gdb-test SPOT } } |