| 1 |
// { dg-do run { target c++14 } } |
| 2 |
// { dg-options "-g -O0" } |
| 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 <experimental/any> |
| 22 |
#include <experimental/optional> |
| 23 |
#include <experimental/string_view> |
| 24 |
#include <string> |
| 25 |
#include <map> |
| 26 |
#include <iostream> |
| 27 |
|
| 28 |
using std::experimental::any; |
| 29 |
using std::experimental::optional; |
| 30 |
using std::experimental::string_view; |
| 31 |
|
| 32 |
int |
| 33 |
main() |
| 34 |
{ |
| 35 |
// Ensure debug info for std::string is issued in the local |
| 36 |
// translation unit, so that GDB won't pick up any alternate |
| 37 |
// std::string notion that might be present in libstdc++.so. |
| 38 |
std::string bah = "hi"; |
| 39 |
(void)bah; |
| 40 |
|
| 41 |
string_view str = "string"; |
| 42 |
// { dg-final { note-test str "\"string\"" } } |
| 43 |
|
| 44 |
optional<int> o; |
| 45 |
// { dg-final { note-test o {std::experimental::optional [no contained value]} } } |
| 46 |
optional<bool> ob{false}; |
| 47 |
// { dg-final { note-test ob {std::experimental::optional = {[contained value] = false}} } } |
| 48 |
optional<int> oi{5}; |
| 49 |
// { dg-final { note-test oi {std::experimental::optional = {[contained value] = 5}} } } |
| 50 |
optional<void*> op{nullptr}; |
| 51 |
// { dg-final { note-test op {std::experimental::optional = {[contained value] = 0x0}} } } |
| 52 |
optional<std::map<int, double>> om; |
| 53 |
om = std::map<int, double>{ {1, 2.}, {3, 4.}, {5, 6.} }; |
| 54 |
// { dg-final { regexp-test om {std::experimental::optional containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } } |
| 55 |
optional<std::string> os{ "stringy" }; |
| 56 |
// { dg-final { note-test os {std::experimental::optional = {[contained value] = "stringy"}} } } |
| 57 |
|
| 58 |
any a; |
| 59 |
// { dg-final { note-test a {std::experimental::any [no contained value]} } } |
| 60 |
any ab(false); |
| 61 |
// { dg-final { note-test ab {std::experimental::any containing bool = {[contained value] = false}} } } |
| 62 |
any ai(6); |
| 63 |
// { dg-final { note-test ai {std::experimental::any containing int = {[contained value] = 6}} } } |
| 64 |
any ap = (void*)nullptr; |
| 65 |
// { dg-final { note-test ap {std::experimental::any containing void * = {[contained value] = 0x0}} } } |
| 66 |
any as = *os; |
| 67 |
// { dg-final { note-test as {std::experimental::any containing std::string = {[contained value] = "stringy"}} } } |
| 68 |
any as2("stringiest"); |
| 69 |
// { dg-final { regexp-test as2 {std::experimental::any containing const char \* = {\[contained value\] = 0x[[:xdigit:]]+ "stringiest"}} } } |
| 70 |
any am = *om; |
| 71 |
// { dg-final { regexp-test am {std::experimental::any containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } } |
| 72 |
|
| 73 |
std::cout << "\n"; |
| 74 |
return 0; // Mark SPOT |
| 75 |
} |
| 76 |
|
| 77 |
// { dg-final { gdb-test SPOT } } |