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_stringstream<...>' cannot bind to a temporary of type 'basic_stringstream<...>' cout << transform( static_cast<stringstream &>(stringstream() << i).str() ); ^ ~~~~~~~~~~~~~~~~~~~ 1 error generated. When g++ 9.2.0 is used on same machine (also on Linux) everything compiles fine.
Seems that changing cast from stringstream & to const stringstream & or to stringstream && solves problem.
The question is if this is compiler bug or maybe clang is more strict about some standard rules?
transform(std::to_string(i))works and IMHO is easier to understand.stdlib=libc++it fails: godbolt.org/z/4iMPgc.using namespace std;+std::string transform(std::string);will cause confusion sooner or later