Skip to content

Latest commit

 

History

History
89 lines (64 loc) · 3.33 KB

nonstandard-behavior.md

File metadata and controls

89 lines (64 loc) · 3.33 KB
descriptiontitlems.datehelpviewer_keywordsms.assetid
Learn more about: Nonstandard Behavior
Nonstandard Behavior
05/06/2019
compatibility and conformance, nonstandard behavior
Microsoft-specific, compiler behavior
nonstandard behavior, conformance and compatibility
a57dea27-dc79-4f64-8a83-017e84841773

Nonstandard Behavior

The following sections list some of the places where the Microsoft implementation of C++ doesn't conform to the C++ standard. The section numbers given below refer to the section numbers in the C++11 standard (ISO/IEC 14882:2011(E)).

The list of compiler limits that differ from those defined in the C++ standard is given in Compiler Limits.

Covariant Return Types

Virtual base classes are not supported as covariant return types when the virtual function has a variable number of arguments. This doesn't conform to section 10.3, paragraph 7 of the C++11 ISO specification. The following sample doesn't compile; it generates compiler error C2688:

// CovariantReturn.cppclassA { virtual A* f(int c, ...); // remove ... }; classB : virtual A { B* f(int c, ...); // C2688 remove ... };

Binding Nondependent Names in Templates

The Microsoft C++ compiler doesn't currently support binding nondependent names when initially parsing a template. This doesn't conform to section 14.6.3 of the C++11 ISO specification. This can cause overloads declared after the template (but before the template is instantiated) to be seen.

#include<iostream>usingnamespacestd;namespaceN { voidf(int) { cout << "f(int)" << endl;} } template <classT> voidg(T) { N::f('a'); // calls f(char), should call f(int) } namespaceN { voidf(char) { cout << "f(char)" << endl;} } intmain() { g('c'); } // Output: f(char)

Function Exception Specifiers

Function exception specifiers other than throw() are parsed but not used. This doesn't conform to section 15.4 of the ISO C++11 specification. For example:

voidf() throw(int); // parsed but not usedvoidg() throw(); // parsed and used

For more information on exception specifications, see Exception Specifications.

char_traits::eof()

The C++ standard states that char_traits::eof must not correspond to a valid char_type value. The Microsoft C++ compiler enforces this constraint for type char, but not for type wchar_t. This doesn't conform to the requirement in Table 62 in section 12.1.1 of the C++11 ISO specification. The example below demonstrates this behavior.

#include<iostream>intmain() { usingnamespacestd; char_traits<char>::int_type int2 = char_traits<char>::eof(); cout << "The eof marker for char_traits<char> is: " << int2 << endl; char_traits<wchar_t>::int_type int3 = char_traits<wchar_t>::eof(); cout << "The eof marker for char_traits<wchar_t> is: " << int3 << endl; }

Storage Location of Objects

The C++ standard (section 1.8 paragraph 6) requires complete C++ objects to have unique storage locations. However with Microsoft C++, there are cases where types without data members will share a storage location with other types for the lifetime of the object.

close