std::string_view constructor & validity outside the place it was defined

39 Views Asked by At

Given the following code

std::string_view foo(){
    std::string_view sv("ABC");
    return sv;
}

int main(){
   std::string_view svv = foo();
}
  1. Is it safe to say that since "ABC" is stored in the static area of the stack, svv is valid since the internal char array is still alive outside the scope of foo?
  2. Is it true that it will be called the constructor (4) at https://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view?
  3. If it were = "ABC", does 1. still hold?
0

There are 0 best solutions below