Non-const reference bound to temporary, Visual Studio bug?

后端 未结 2 798
慢半拍i
慢半拍i 2020-11-22 05:08

I ran into this while compiling some portable code in gcc. Basically this strange code compiles in Visual studio which really just blows my mind:



        
2条回答
  •  没有蜡笔的小新
    2020-11-22 05:33

    As others said, this is due to Microsoft C++ extension. Though /Za flag is not recommended as it can break things.

    Instead use the /permissive- switch for better standards compliancy and you will get healthy errors for these cases. Note that this flag is available since VS 2017.

    The switch /Za does not support certain key Microsoft SDK header files. By contrast /permissive- offers a useful conformance mode where input C++ code is interpreted according to ISO C++ rules but also allows conforming extensions necessary to compile C++ on targets supported by Visual C++.

    More info is on Visual C++ Team Blog.

提交回复
热议问题