Matthieu M.
Matthieu M.

Reputation: 300399

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 provide one answer per discrepancy (check for duplicate) and for each:

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

Upvotes: 3

Views: 390

Answers (5)

Matthieu M.
Matthieu M.

Reputation: 300399

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.

Upvotes: 0

James McNellis
James McNellis

Reputation: 355347

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.

Upvotes: 1

Bo Persson
Bo Persson

Reputation: 92381

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

Remedy: use warning level 4

Upvotes: 4

Matteo Italia
Matteo Italia

Reputation: 126957

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.

Upvotes: 6

Related Questions