I know from this answer that string literals are allocated statically. But is the following string concatenation also safe to use?
void someFunction(std::string& foo) {
functionTakingCString(("start " + foo + " end").c_str());
}
Follow Up Question: As stated in the comments, this would be indeed unsafe when functionTakingCString would store that pointer. In this case, would the following be valid:
void someFunction(std::string& foo) {
std::string bar = "start " + foo + " end";
functionTakingCString(bar.c_str());
}