2019-08-24 06:26:49 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wno-dangling-gsl -Wreturn-stack-address -verify %s
|
2019-08-24 06:21:33 +08:00
|
|
|
|
|
|
|
struct [[gsl::Owner(int)]] MyIntOwner {
|
|
|
|
MyIntOwner();
|
|
|
|
int &operator*();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct [[gsl::Pointer(int)]] MyIntPointer {
|
|
|
|
MyIntPointer(int *p = nullptr);
|
|
|
|
MyIntPointer(const MyIntOwner &);
|
|
|
|
int &operator*();
|
|
|
|
MyIntOwner toOwner();
|
|
|
|
};
|
|
|
|
|
|
|
|
int &f() {
|
|
|
|
int i;
|
|
|
|
return i; // expected-warning {{reference to stack memory associated with local variable 'i' returned}}
|
|
|
|
}
|
|
|
|
|
|
|
|
MyIntPointer g() {
|
|
|
|
MyIntOwner o;
|
|
|
|
return o; // No warning, it is disabled.
|
|
|
|
}
|