Skip to content

Commit 8442d6b

Browse files
authored
Merge pull request #11119 from swiftlang/egorzhdan/lifetimebound-syntax-stable
🍒[Clang] Use [[clang::lifetimebound]] syntax when supported
2 parents 13ee9be + e40b842 commit 8442d6b

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

clang/lib/Headers/lifetimebound.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@
1010
#ifndef __LIFETIMEBOUND_H
1111
#define __LIFETIMEBOUND_H
1212

13+
#if defined(__cplusplus) && defined(__has_cpp_attribute)
14+
#define __use_cpp_spelling(x) __has_cpp_attribute(x)
15+
#else
16+
#define __use_cpp_spelling(x) 0
17+
#endif
18+
19+
#if __use_cpp_spelling(clang::lifetimebound)
20+
#define __lifetimebound [[clang::lifetimebound]]
21+
#else
1322
#define __lifetimebound __attribute__((lifetimebound))
23+
#endif
1424

25+
#if __use_cpp_spelling(clang::lifetime_capture_by)
26+
#define __lifetime_capture_by(X) [[clang::lifetime_capture_by(X)]]
27+
#else
1528
#define __lifetime_capture_by(X) __attribute__((lifetime_capture_by(X)))
29+
#endif
1630

31+
#if __use_cpp_spelling(clang::noescape)
32+
#define __noescape [[clang::noescape]]
33+
#else
1734
#define __noescape __attribute__((noescape))
35+
#endif
1836

1937
#endif /* __LIFETIMEBOUND_H */

clang/test/Headers/lifetimebound.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
// Verify that we can include <lifetimebound.h>
5+
#include <lifetimebound.h>
6+
7+
struct foo {};
8+
9+
struct foo* get_foo(char *ptr __lifetimebound);
10+
11+
void non_escaping(char *ptr __noescape);

clang/test/Headers/lifetimebound.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
struct has_lifetimebound_method {
88
const char* get_ptr(char* ptr __lifetimebound) const;
9+
const char* get_ptr() const __lifetimebound;
910
};
1011

1112
struct has_lifetime_capture_by_method {

0 commit comments

Comments
 (0)