Error when casting temporary object to non-const reference
问题 Here is a reproducible example taken from question about using temporary stringstream object: #include <sstream> #include <string> #include <iostream> using namespace std; std::string transform(std::string); int main() { int i{}; cout << transform( static_cast<stringstream &>(stringstream() << i).str() ); } When trying to compile with clang version 9.0.0 under MacOS High Sierra I got following error: $ clang++ -std=c++11 x.cc -c x.cc:12:24: error: non-const lvalue reference to type 'basic