Assigning a non-constant link

VS2015 Update 3 compiles this without errors and without warning. Nevertheless, I got the impression that temporary persons can only be associated with references to constants. Is this a mismatch, or am I not understanding something?

struct Foo {}; Foo Func6() { return Foo(); } TEST(Arguments, NonConstReference) { Foo& bob = Func6(); } 

EDIT

The question related to marcinj is the same problem, although this question is not specific to VS2015 and was not located when I typed it.

I tested with / W 4 to find out if I received a warning and did not see it, but check it again. I find it now. When opening project properties to configure parameters, VS2015 has the habit of showing the properties dialog set for a different assembly configuration than the one currently selected, the most useless behavior that has caught me many times (and I'm sure I will continue to do this).

As mentioned in this other question using forbidden language extensions (/ Za), this error is an error, but, unfortunately, is not a suitable solution, since compiling Microsoft's own headers will not compile.

+5
source share
1 answer

The MSVC compiler has a non-standard extension enabled by default, which allows temporary links to const links. To disable this, use the /Za command-line option or the corresponding project property.

+7
source

Source: https://habr.com/ru/post/1260286/


All Articles