D
D
Daniil Demidko2017-01-18 14:01:31
C++ / C#
Daniil Demidko, 2017-01-18 14:01:31

Why does VS 2015 misinterpret l-value references?

void f(std::string &i) {}

int main()
{
    f(std::string());
}

We pass an rvalue value to the lvalue reference, but VS sees no problems. GCC immediately throws an error.
Moreover, everything works correctly for POD, and throws errors, for example, the similar code with int VS no longer skips.
How to set up normal error checking?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2017-01-18
@Daniro_San

VS allows you to shoot yourself in the foot if you feel like it.
1. Don't write like this if you didn't need it (saving a line of code, right?)
2. Pass by constant reference, then there will be no problems in GCC either.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question