[clang] [clang] Update string and string_view in lifetimebound tests (PR #111737)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 11:49:12 PDT 2024
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/111737
>From 6e8a4c942708aa11b0c2a735881b5a368f97580d Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 9 Oct 2024 18:41:19 +0000
Subject: [PATCH 1/2] [clang] Update string and string_view in lifetimebound
tests
---
clang/test/SemaCXX/attr-lifetimebound.cpp | 33 +++++++++++------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 0fb997a5671085..edeb33eaeb1dd8 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -75,23 +75,26 @@ namespace usage_ok {
}
}
-# 1 "<std>" 1 3
namespace std {
using size_t = __SIZE_TYPE__;
- struct string {
- string();
- string(const char*);
+ template<typename T>
+ struct basic_string {
+ basic_string();
+ basic_string(const T*);
char &operator[](size_t) const [[clang::lifetimebound]];
};
- string operator""s(const char *, size_t);
-
- struct string_view {
- string_view();
- string_view(const char *p [[clang::lifetimebound]]);
- string_view(const string &s [[clang::lifetimebound]]);
+ using string = basic_string<char>;
+ string operator""s(const char *, size_t); // expected-warning {{}}
+
+ template<typename T>
+ struct basic_string_view {
+ basic_string_view();
+ basic_string_view(const T *p);
+ basic_string_view(const string &s [[clang::lifetimebound]]);
};
- string_view operator""sv(const char *, size_t);
+ using string_view = basic_string_view<char>;
+ string_view operator""sv(const char *, size_t); // expected-warning {{}}
struct vector {
int *data();
@@ -100,7 +103,6 @@ namespace std {
template<typename K, typename V> struct map {};
}
-# 68 "attr-lifetimebound.cpp" 2
using std::operator""s;
using std::operator""sv;
@@ -112,7 +114,7 @@ namespace p0936r0_examples {
void f() {
std::string_view sv = "hi";
std::string_view sv2 = sv + sv; // expected-warning {{temporary}}
- sv2 = sv + sv; // FIXME: can we infer that we should warn here too?
+ sv2 = sv + sv; // expected-warning {{object backing the pointer}}
}
struct X { int a, b; };
@@ -238,11 +240,6 @@ template <class T> T *addressof(T &arg) {
&const_cast<char &>(reinterpret_cast<const volatile char &>(arg)));
}
-template<typename T>
-struct basic_string_view {
- basic_string_view(const T *);
-};
-
template <class T> struct span {
template<size_t _ArrayExtent>
span(const T (&__arr)[_ArrayExtent]) noexcept;
>From 9db69e5f435567bf83404e71ec86af37cee25bb3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 9 Oct 2024 18:48:59 +0000
Subject: [PATCH 2/2] add warning for user-defined literal
---
clang/test/SemaCXX/attr-lifetimebound.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp
index edeb33eaeb1dd8..bdc58171917375 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -85,7 +85,7 @@ namespace std {
char &operator[](size_t) const [[clang::lifetimebound]];
};
using string = basic_string<char>;
- string operator""s(const char *, size_t); // expected-warning {{}}
+ string operator""s(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
template<typename T>
struct basic_string_view {
@@ -94,7 +94,7 @@ namespace std {
basic_string_view(const string &s [[clang::lifetimebound]]);
};
using string_view = basic_string_view<char>;
- string_view operator""sv(const char *, size_t); // expected-warning {{}}
+ string_view operator""sv(const char *, size_t); // expected-warning {{user-defined literal suffixes not starting with '_' are reserved}}
struct vector {
int *data();
More information about the cfe-commits
mailing list