Skip to content

Commit a3638f1

Browse files
authored
[clang] Update string and string_view in lifetimebound tests (#111737)
Removes pragmas like `# 1 "<std>" 1 3` to make line numbers in failing tests more accurate. Use `basic_string_view` instead `string_view` to kick in GSL owner/pointer auto inference.
1 parent 4ddc756 commit a3638f1

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

clang/test/SemaCXX/attr-lifetimebound.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,26 @@ namespace usage_ok {
7575
}
7676
}
7777

78-
# 1 "<std>" 1 3
7978
namespace std {
8079
using size_t = __SIZE_TYPE__;
81-
struct string {
82-
string();
83-
string(const char*);
80+
template<typename T>
81+
struct basic_string {
82+
basic_string();
83+
basic_string(const T*);
8484

8585
char &operator[](size_t) const [[clang::lifetimebound]];
8686
};
87-
string operator""s(const char *, size_t);
88-
89-
struct string_view {
90-
string_view();
91-
string_view(const char *p [[clang::lifetimebound]]);
92-
string_view(const string &s [[clang::lifetimebound]]);
87+
using string = basic_string<char>;
88+
string operator""s(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
89+
90+
template<typename T>
91+
struct basic_string_view {
92+
basic_string_view();
93+
basic_string_view(const T *p);
94+
basic_string_view(const string &s [[clang::lifetimebound]]);
9395
};
94-
string_view operator""sv(const char *, size_t);
96+
using string_view = basic_string_view<char>;
97+
string_view operator""sv(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
9598

9699
struct vector {
97100
int *data();
@@ -100,7 +103,6 @@ namespace std {
100103

101104
template<typename K, typename V> struct map {};
102105
}
103-
# 68 "attr-lifetimebound.cpp" 2
104106

105107
using std::operator""s;
106108
using std::operator""sv;
@@ -112,7 +114,7 @@ namespace p0936r0_examples {
112114
void f() {
113115
std::string_view sv = "hi";
114116
std::string_view sv2 = sv + sv; // expected-warning {{temporary}}
115-
sv2 = sv + sv; // FIXME: can we infer that we should warn here too?
117+
sv2 = sv + sv; // expected-warning {{object backing the pointer}}
116118
}
117119

118120
struct X { int a, b; };
@@ -238,11 +240,6 @@ template <class T> T *addressof(T &arg) {
238240
&const_cast<char &>(reinterpret_cast<const volatile char &>(arg)));
239241
}
240242

241-
template<typename T>
242-
struct basic_string_view {
243-
basic_string_view(const T *);
244-
};
245-
246243
template <class T> struct span {
247244
template<size_t _ArrayExtent>
248245
span(const T (&__arr)[_ArrayExtent]) noexcept;

0 commit comments

Comments
 (0)