Is a copy-on-return operation executed prior or after lock_guard destructor? [duplicate]
问题 This question already has answers here : C++ return value created before or after auto var destruction? (2 answers) in C++ which happens first, the copy of a return object or local object's destructors? [duplicate] (4 answers) Closed 2 years ago . Is the get_a() function safe for race-conditions or do I need to explicitly copy str_ as in get_b() in order to have a thread-safe function? class Class { public: auto get_a() -> std::string { auto&& guard = std::lock_guard{mutex_}; return str_; }