struct test{
char c_arr[1];
};
test array[1] = {{1}};
test get(int index){
return array[index];
}
int main(){
char* a = get(0).c_arr;
return 0;
}
Compiling this with g++
has no warnings but with clang++
prints the following:
warning: temporary whose address is used as value of local variable 'a' will be destroyed at the end of the full-expression
Is this incorrect? does get(0).c_arr
not return a pointer to a global array?
or does get(0)
return a temporary variable and the compiler thinks c_arr
is just an instance of it, and not global, by mistake?
Edit
Why passing this temp variable to a function works without warnings?
void call(char* in){}
int main(){
call(get(0).c_arr);
return 0;
}