开发者

Visual Studio 2010: extensions / discrepancies

Visual Studio 2010 features a number of extensions (activated by default) / discrepancies with regard to the C++ Standard.

Such discrepancies can be surprising, and elicit a different behavior than other behavior. VS is notably famous for being extremely lax in template code validation, and template code that was accepted and compiled by VS will often be rejected outright by more compliant compilers (CLang, Comeau, icc, gcc, ... to name a few).

The goal of this question is to provide a reference (thus the FAQ tag) for these discrepancies.

Please 开发者_StackOverflow中文版provide one answer per discrepancy (check for duplicate) and for each:

  • Explain the discrepancy
  • Tell us if it is possible to disable this (and if so, how)
  • Explain the consequences (apart from the mere rejection)

Note: C++0x is the next standard, so avoid listing C++0x extensions, since they'll be standard soon

From @Matteo Italia: Visual Studio Compliance Page


First of all, I'd link Microsoft's take on this topic.

All the Microsoft language extensions can be found here; there's also a page where the areas of the language where VC++ is not compliant to the standard are listed.


By default the compiler allows binding a temporary to a non-const reference.

Remedy: use warning level 4


Visual C++ does not fully support value initialization (or rather, there are bugs in all current versions of Visual C++, from Visual C++ 2005 through Visual C++ 2010 SP1).

There are several reported bugs about this (see also this answer to another question).

Consequence: some forms of code that should value initialize an object leave the object or some part of the object uninitialized.

Workaround: do not rely on value initialization.


Discrepancy: Visual Studio does not bind non-dependent names in templates during first evaluation.

The Standard requires two-phases evaluation:

  • First: check basic templates well-formedness, bind non-dependent names (which comprises overload resolution)
  • Second: Instantiation proper

Disable ? It is not subject to any option or switch, it is simply not implemented.

Consequences:

Visual Studio only does the second phase, which affects:

  • Errors in template code are detected at instantiation only, so you'd better instantiate all the templates you write early (think of it as compilation unit test).
  • Missing template or typename keywords are not detected by VS
  • Overloads declared after the`template may be picked up by overload resolution. Not so much of an issue since reverting the include order would produce the same result.


I use a blog as a notebook for non-complicance issues I find in VS2005. I don't see a point in reposting the whole thing here

http://atarasevich.blogspot.com/2008/02/microsoft-vs2005-c-non-compliance.html

http://atarasevich.blogspot.com/2008/02/microsoft-vs2005-c-non-compliance_07.html

http://atarasevich.blogspot.com/2008/02/microsoft-vs2005-c-non-compliance_08.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜