// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'FILE *' (aka 'int *') or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
gsl::owner<FILE*>fileFactory2(){returnstd::fopen("new_file.txt","w");}// Ok
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'int *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
gsl::owner<int*>arrayFactory2(){return(int*)std::malloc(100);}// Ok
void*dataFactory1(){returnstd::malloc(100);}
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: returning a newly created resource of type 'void *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
gsl::owner<void*>dataFactory2(){returnstd::malloc(100);}// Ok
voidtest_resource_creators(){
constunsignedintByteCount=25*sizeof(int);
intBad=42;
int*IntArray1=(int*)std::malloc(ByteCount);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
int*IntArray2=static_cast<int*>(std::malloc(ByteCount));// Bad
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
void*IntArray3=std::malloc(ByteCount);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>'
int*IntArray4=(int*)::malloc(ByteCount);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
int*IntArray5=static_cast<int*>(::malloc(ByteCount));// Bad
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'int *' with a newly created 'gsl::owner<>'
void*IntArray6=::malloc(ByteCount);
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'void *' with a newly created 'gsl::owner<>'
gsl::owner<int*>IntArray7=(int*)malloc(ByteCount);// Ok
gsl::owner<void*>IntArray8=malloc(ByteCount);// Ok
gsl::owner<int*>IntArray9=&Bad;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'int *'
nonOwningCall((int*)malloc(ByteCount),25);
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
nonOwningCall((int*)::malloc(ByteCount),25);
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: initializing non-owner argument of type 'int *' with a newly created 'gsl::owner<>'
consumesResource((int*)malloc(ByteCount),25);// Ok
consumesResource((int*)::malloc(ByteCount),25);// Ok
testNonCasted(malloc(ByteCount));
// CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'void *' with a newly created 'gsl::owner<>'
testNonCastedOwner(gsl::owner<void*>(malloc(ByteCount)));// Ok
testNonCastedOwner(malloc(ByteCount));// Ok
FILE*File1=std::fopen("test_name.txt","w+");
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
FILE*File2=::fopen("test_name.txt","w+");
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
gsl::owner<FILE*>File3=::fopen("test_name.txt","w+");// Ok
FILE*File4;
File4=::fopen("test_name.txt","w+");
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: assigning newly created 'gsl::owner<>' to non-owner 'FILE *' (aka 'int *')
gsl::owner<FILE*>File5;
File5=::fopen("test_name.txt","w+");// Ok
File5=File1;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected assignment source to be of type 'gsl::owner<>'; got 'FILE *' (aka 'int *')
gsl::owner<FILE*>File6=File1;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: expected initialization with value of type 'gsl::owner<>'; got 'FILE *' (aka 'int *')
FILE*File7=tmpfile();
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: initializing non-owner 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
gsl::owner<FILE*>File8=tmpfile();// Ok
nonOwningCall(::fopen("test_name.txt","r"));
// CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
nonOwningCall(std::fopen("test_name.txt","r"));
// CHECK-MESSAGES: [[@LINE-1]]:17: warning: initializing non-owner argument of type 'FILE *' (aka 'int *') with a newly created 'gsl::owner<>'
consumesResource(::fopen("test_name.txt","r"));// Ok