Articles . Notes: (V)C++ Gotchas
Odd behavior & Microsoft C++ Compiler bugs that I came across in various projects. Even though some turned out not to be actual bugs, all of them are documented in the form of Microsoft Connect bug reports.
MSVC++ 2010 Compiler Issues
See 'Details' in the linked MS Connect Bug Reports for corresponding example code.
- [C++] Reference default argument falsely converted to pointer on instantiation of more than 2 explicit specializations
[Fixed in VC++ 2012]
- [C++] No warning when returning r-value-references to locals / temporaries [Fixed in VC++ 2012]
- [C++] __alignof() fails to properly evalute alignment of dependent types !!! [Fixed in VC++ 2012]
Workaround: Always evaluate sizeof() before evaluating _alignof(), e.g. using this template wrapper.
- [C++] Failure to compile functions taking template template arguments of dependent types [Fixed in VC++ 2012]
- [C++] Loop unrolling dependent on operator of comparison [Not fixed yet]
Workaround: Always use operator < in loop condition to ensure proper unrolling.
Odd MSVC++ 2010 Compiler Behavior
Even though the following issues turned out not to be actual bugs, they document some odd, yet standard-conformant behavior that you might come across some time.
- [C++] Failure to deduce template arguments on class template / method name collision
- [C++] Dependent static constant variables of class templates not initialized correctly !!!
- [C++] Temporary strings implicitly constructed take l-value path instead of r-value path [Fixed in VC++ 2012]
Workaround: Explicitly construct temporary objects to take advantage of move semantics.