I have this code in VS2019, which compiled and ran fine under C++14:
class Parser
{
void Parse(istream& input)
{
// Do the parsing
}
}
class ParserTests
{
void TestTheParser()
{
constexpr auto TheText = "Some text to parse";
auto parser = Parser{};
// Create a temporary stringstream around the text to parse:
// This line compiles and runs fine in VS2019 with C++14 language
parser.Parse(stringstream{ TheText });
}
}
I recently switched my code to C++20, and I suddenly get the following compiler error when I call parser.Parse():
cannot convert argument 1 from std::stringstream to std::istream&
If I change my test code to use a real variable instead of an inline temporary:
// Seat the stringstream to a variable, before calling Parse
auto strm = stringstream{ TheText };
parser.Parse(strm);
then my code once again starts working.
Is this a bug in Visual Studio's support of C++20? Or is this a new language restriction that I do not yet understand? I have a lot of test code written like this, and I'm a bit annoyed at the prospect of changing every single one.