Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-99287.C

raw
1 // PR c++/99287
2 // { dg-do compile { target c++20 } }
3
4 namespace std {
5 struct source_location {
6 static consteval source_location
7 current(const void *__p = __builtin_source_location()) {
8 source_location __ret;
9 __ret._M_impl = static_cast<const __impl *>(__p);
10 return __ret;
11 }
12 constexpr const char *function_name() {
13 return _M_impl ? _M_impl->_M_function_name : "";
14 }
15 struct __impl {
16 const char *_M_file_name;
17 const char *_M_function_name;
18 unsigned _M_line;
19 unsigned _M_column;
20 } const *_M_impl;
21 };
22 struct char_traits {
23 static constexpr long length(const char *__s) {
24 return __builtin_strlen(__s);
25 }
26 };
27 template <typename _CharT, typename _Traits = char_traits>
28 class basic_string_view {
29 public:
30 using traits_type = _Traits;
31 using size_type = unsigned long;
32 constexpr basic_string_view(const _CharT *__str)
33 : _M_len{traits_type::length(__str)}, _M_str{__str} {}
34 constexpr size_type find(const _CharT *, size_type, size_type) const noexcept;
35 constexpr size_type find(_CharT *__str) {
36 long __trans_tmp_1 = traits_type::length(__str);
37 return find(__str, 0, __trans_tmp_1);
38 }
39 long _M_len;
40 const _CharT *_M_str;
41 };
42 using string_view = basic_string_view<const char>;
43 template <typename _CharT, typename _Traits>
44 constexpr unsigned long
45 basic_string_view<_CharT, _Traits>::find(const _CharT *__str, size_type,
46 size_type __n) const noexcept {
47 int __trans_tmp_2;
48 const _CharT *__first = _M_str;
49 size_type __len = _M_len;
50 while (__len >= __n) {
51 __trans_tmp_2 = __builtin_memcmp(__first, __str, __n);
52 if (__trans_tmp_2 == 0)
53 return __first - _M_str;
54 __len = _M_str - ++__first;
55 }
56 }
57 } // namespace std
58 template <typename> consteval auto f() {
59 return std::string_view{std::source_location::current().function_name()};
60 }
61 int main() { constexpr auto s = f<int>().find("int"); }