llvm-for-llvmta/tools/clang/test/Sema/warn-lifetime-analysis-nocf...

24 lines
537 B
C++
Raw Normal View History

2022-04-25 13:02:35 +02:00
// RUN: %clang_cc1 -fsyntax-only -Wno-dangling-gsl -Wreturn-stack-address -verify %s
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.
}