C PDF
C PDF
NOTE
This developer documentation applies to Visual Studio 2015 and Visual Studio 2017.
If you are looking for a Visual C++ redistributable package so that you can run a program, go to the Microsoft Download
Center and enter Visual C++ in the search box.
Microsoft Visual C++, usually shortened to Visual C++ or MSVC, is the name for the C++, C, and assembly
language development tools and libraries available as part of Visual Studio on Windows. These tools and libraries
let you create Universal Windows Platform (UWP ) apps, native Windows desktop and server applications, cross-
platform libraries and apps that run on Windows, Linux, Android, and iOS, as well as managed apps and libraries
that use the .NET Framework. You can use Visual C++ to write anything from simple console apps to the most
sophisticated and complex apps for Windows desktop, from device drivers and operating system components to
cross-platform games for mobile devices, and from the smallest IoT devices to multi-server high performance
computing in the Azure cloud.
Languages reference
C++ Language Reference
C/C++ Preprocessor Reference
C Language Reference
Compiler Intrinsics and Assembly Language
See also
C Language Reference
C Run-Time Library Reference
Compiler Intrinsics and Assembly Language
What's New for Visual C++ in Visual Studio 2017
10/5/2018 • 28 minutes to read • Edit Online
Visual Studio 2017 brings many updates and fixes to the Visual C++ environment. We've fixed over 250 bugs and
reported issues in the compiler and tools, many submitted by customers through the Report a Problem and
Provide a Suggestion options under Send Feedback. Thank you for reporting bugs! For more information on
what's new in all of Visual Studio, please visit What's new in Visual Studio 2017.
C++ compiler
C++ conformance improvements
In this release, we've updated the C++ compiler and standard library with enhanced support for C++11 and
C++14 features, as well as preliminary support for certain features expected to be in the C++17 standard. For
detailed information, see C++ Conformance Improvements in Visual Studio 2017.
Visual Studio 2017 version 15.5: The compiler supports about 75% of the features that are new in C++17,
including structured bindings, constexpr lambdas, if constexpr , inline variables, fold expressions, and adding
noexcept to the type system. These are available under the /std:c++17 option. For more information, see C++
Conformance Improvements in Visual Studio 2017
Visual Studio 2017 version 15.7: The MSVC compiler toolset in Visual Studio version 15.7 now conforms with
the C++ Standard. For more information, see Announcing: MSVC Conforms to the C++ Standard and Visual C++
Language Conformance.
New compiler options
/permissive-: Enable all strict standards conformance compiler options and disable most Microsoft-specific
compiler extensions (but not __declspec(dllimport) , for example). This option is on by default in Visual
Studio 2017 version 15.5. The /permissive- conformance mode includes support for two-phase name
lookup. For more information, see C++ Conformance Improvements in Visual Studio 2017.
/diagnostics: Enable display of the line number, the line number and column, or the line number and
column and a caret under the line of code where the diagnostic error or warning was found.
/debug:fastlink: Enable up to 30% faster incremental link times (vs. Visual Studio 2015) by not copying all
debug information into the PDB file. The PDB file instead points to the debug information for the object
and library files used to create the executable. See Faster C++ build cycle in VS "15" with /Debug:fastlink
and Recommendations to speed C++ builds in Visual Studio.
Visual Studio 2017 allows using /sdl with /await. We removed the /RTC limitation with Coroutines.
Visual Studio 2017 version 15.3:
/std:c++14 and /std:c++latest: These compiler options enable you to opt-in to specific versions of the ISO
C++ programming language in a project. Most of the new draft standard features are guarded by the
/std:c++latest option.
/std:c++17 enables the set of C++17 features implemented by the compiler. This option disables compiler
and standard library support for features that are changed or new in versions of the Working Draft and
defect updates of the C++ Standard after C++17. To enable those features, use /std:c++latest.
Codegen, security, diagnostics and versioning
This release brings several improvements in optimization, code generation, toolset versioning, and diagnostics.
Some notable improvements include:
Improved code generation of loops: Support for automatic vectorization of division of constant integers, better
identification of memset patterns.
Improved code security: Improved emission of buffer overrun compiler diagnostics, and /guard:cf now guards
switch statements that generate jump tables.
Versioning: The value of the built-in preprocessor macro _MSC_VER is now being monotonically updated at
every Visual C++ toolset update. For more information, see Visual C++ Compiler Version.
New toolset layout: The compiler and related build tools have a new location and directory structure on your
development machine. The new layout enables side-by-side installations of multiple versions of the compiler.
For more information, see Compiler Tools Layout in Visual Studio "15".
Improved diagnostics: The output window now shows the column where an error occurs. For more
information, see C++ compiler diagnostics improvements in VS "15" Preview 5.
When using co-routines, the experimental keyword yield (available under the /await option) has been
removed. Your code should be updated to use co_yield instead. For more information, see the Visual C++
Team blog.
Visual Studio 2017 version 15.3:
Additional improvements to diagnostics in the compiler. For more information, see Diagnostic Improvements in
Visual Studio 2017 15.3.0.
Visual Studio 2017 version 15.5:
Visual C++ runtime performance continues to improve due to better generated code quality. This means that you
can simply recompile your code, and your app runs faster. Some of the compiler optimizations are brand new, such
as the vectorization of conditional scalar stores, the combining of calls sin(x) and cos(x) into a new sincos(x) ,
and the elimination of redundant instructions from the SSA Optimizer. Other compiler optimizations are
improvements to existing functionality such as vectorizer heuristics for conditional expressions, better loop
optimizations, and float min/max codegen. The linker has a new and faster /OPT:ICF implementation which can
result in up to 9% link time speedups, and there are other perf fixes in incremental linking. For more information,
see /OPT (Optimizations) and /INCREMENTAL (Link Incrementally).
Visual C++ supports Intel's AVX-512, including the Vector Length instructions that bring new functions in AVX-
512 to 128- and 256-bit wide registers.
The /Zc:noexceptTypes- option can be used to revert to the C++14 version of noexcept while using C++17 mode
in general. This enables you to update your source code to conform to C++17 without having to rewrite all your
throw() code at the same time. For more information, see Dynamic exception specification removal and noexcept.
Other Libraries
Open source library support
Vcpkg is an open-source command line tool that greatly simplifies the process of acquiring and building open
source C++ static libs and DLLS in Visual Studio. For more information, see vcpkg: A package manager for C++.
Visual Studio 2017 version 15.5:
CPPRest SDK 2.9.0
The CPPRestSDK, a cross-platform web API for C++, has been updated to version 2.9.0. For more information,
see CppRestSDK 2.9.0 is available on GitHub.
ATL
Yet another set of name-lookup conformance fixes
Existing move constructors and move assignment operators are now properly marked as non-throwing
Un-suppress valid warning C4640 about thread safe init of local statics in atlstr.h
Thread Safe Initialization of local statics was automatically turned off in the XP toolset when [using ATL AND
building a DLL ]. This is no longer the case. You can add /Zc:threadSafeInit- in your Project settings if having
thread safe initialization off is desired.
Visual C++ runtime
New header "cfguard.h" for Control Flow Guard symbols.
C++ IDE
Configuration change performance is now better for C++ native projects and much better for C++/CLI
projects. When a solution configuration is activated for the first time it will now be faster and all subsequent
activations of this solution configuration will be almost instantaneous.
Visual Studio 2017 version 15.3:
Several project and code wizards have been rewritten in the signature dialog style.
Add Class now launches the Add Class wizard directly. All of the other items that were previously here are
now available under Add > New Item.
Win32 projects are now under the Windows Desktop category in the New Project dialog.
The Windows Console and Desktop Application templates now create the projects without displaying a
wizard. There's a new Windows Desktop Wizard under the same category that displays the same options as
the old Win32 Console Application wizard.
Visual Studio 2017 version 15.5:
Several C++ operations that use the IntelliSense engine for refactoring and code navigation run much faster. The
following numbers are based on the Visual Studio Chromium solution with 3500 projects:
Rename 5.3x
C++ now supports Ctrl+Click Go To Definition, making mouse navigation to definitions easy. The Structure
Visualizer from the Productivity Power Tools pack is now also included in the product by default.
IntelliSense
The new SQLite-based database engine is now being used by default. This will speed up database
operations like Go To Definition and Find All References, and will significantly improve initial solution
parse time. The setting has been moved to Tools > Options > Text Editor > C/C++ > Advanced (it was
formerly under ...C/C++ | Experimental).
We've improved IntelliSense performance on projects and files not using precompiled headers - an
Automatic Precompiled Header will be created for headers in the current file.
We've added error filtering and help for IntelliSense errors in the error list. Clicking on the error column
now allows for filtering. Also, clicking on the specific errors or pressing F1 will launch an online search for
the error message.
Added the ability to filter Member List items by kind.
Added a new experimental Predictive IntelliSense feature that provides contextually-aware filtering of what
appears in the Member List. See C++ IntelliSense Improvements - Predictive IntelliSense & Filtering
Find All References (Shift+F12) now helps you get around easily, even in complex codebases. It provides
advanced grouping, filtering, sorting, searching within results, and (for some languages) colorization, so you
can get a clear understanding of your references. For C++, the new UI includes information about whether we
are reading from or writing to a variable.
The Dot-to-Arrow IntelliSense feature has been moved from experimental to advanced, and is now enabled by
default. The editor features Expand Scopes and Expand Precedence have also been moved from
experimental to advanced.
The experimental refactoring features Change Signature and Extract Function are now available by default.
The experimental 'Faster project load' feature for C++ projects. The next time you open a C++ project it will
load faster, and the time after that it will load really fast!
Some of these features are common to other languages, and some are specific to C++. For more information
about these new features, see Announcing Visual Studio "15".
Visual Studio 1027 version 15.7: Support added for ClangFormat. For more information, see ClangFormat
Support in Visual Studio 2017.
Visual Studio 2017 version 15.3: Support added for the CMake Ninja generator.
Visual Studio 2017 version 15.5: Support added for importing existing CMake caches.
Visual Studio 2017 version 15.7: Support added for CMake 3.11, code analysis in CMake projects, Targets view
in Solution Explorer, options for cache generation, and single file compilation. For more information, see CMake
Support in Visual Studio and CMake projects in Visual C++.
Unit testing
Visual Studio 2017 version 15.5:
Google Test Adapter and Boost.Test Adapter are now available as components of the Desktop Development
with C++ workload, and are integrated with Test Explorer. CTest support is added for Cmake projects (using
Open Folder) although full integration with Test Explorer is not yet available. For more information, see Writing
unit tests for C/C++.
Visual Studio 2017 version 15.6:
Support added for Boost.Test dynamic library support.
A Boost.Test item template is now available in the IDE.
For more information, see Boost.Test Unit Testing: Dynamic Library support and New Item Template.
Visual Studio 2017 version 15.7:
CodeLens supported added for C++ unit test projects. For more information, see Announcing CodeLens for C++
Unit Testing.
Search and filter in the object table: Provides a quick and easy way to find the resources you're looking
for.
Resource History: This new view provides a streamlined way of seeing the entire modification history of a
resource as it was used during the rendering of a captured frame. To invoke the history for any resource,
simply click the clock icon next to any resource hyperlink.
This will display the new Resource History tool window, populated with the change history of the
resource.
Note that if your frame was captured with full call stack capturing enabled (Visual Studio > Tools >
Options under Graphics Diagnostics), then the context of each change event can be quickly deduced and
inspected within your Visual Studio project.
API Statistics: View a high-level summary of API usage in your frame. This can be handy in discovering
calls you may not realize you’re making at all or calls you are making too much. This window is available via
View > API Statistics in Visual Studio Graphics Analyzer.
Memory Statistics: View how much memory the driver is allocating for the resources you create in the
frame. This window is available via View > Memory Statistics in Visual Studio Graphics Analyzer.
Data can be copied to a CSV file for viewing in a spreadsheet by right-clicking and choosing Copy All.
Frame Validation: The new errors and warnings list provides an easy way to navigate your event list
based on potential issues detected by the Direct3D debug layer. Click View > Frame Validation in Visual
Studio Graphics Analyzer to open the window. Then click Run Validation to start the analysis. It can take
several minutes to complete, depending on the frame's complexity.
Frame Analysis for D3D12: Use Frame Analysis to analyze draw call performance with directed "what-if"
experiments. Switch to the Frame Analysis tab and run analysis to view the report. For more details, watch
the GoingNative 25: Visual Studio Graphics Frame Analysis video.
GPU Usage Improvements: Open traces taken via the Visual Studio GPU Usage profiler with either GPU
View or the Windows Performance Analyzer (WPA) tool for more detailed analysis. If you have the
Windows Performance Toolkit installed there will be two hyperlinks, one for WPA and other for GPU View,
at the bottom right of the session overview.
Traces opened in GPU View via this link support synchronized zooming and panning in the timeline
between VS and GPU View. A checkbox in VS is used to control whether synchronization is enabled or not.
Install C++ support in Visual Studio
9/24/2018 • 3 minutes to read • Edit Online
If you haven't downloaded and installed Visual Studio 2017 and the Visual C++ tools yet, here's how to get started.
Prerequisites
A broadband internet connection. The Visual Studio installer can download several gigabytes of data.
A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 10 for the best
development experience. Make sure that the latest updates are applied to your system before you install
Visual Studio.
Enough free disk space. Visual Studio requires at least 7GB of disk space, and can take 50GB or more if
many common options are installed. We recommend you install it on your C: drive.
For details on the disk space and operating system requirements, see Visual Studio Product Family System
Requirements. The installer reports how much disk space is required for the options you select.
TIP
The Community edition is for individual developers, classroom learning, academic research, and open source
development. For other uses, install Visual Studio 2017 Professional or Visual Studio 2017 Enterprise.
2. Find the installer file you downloaded and run it. It may be displayed in your browser, or you may find it in
your Downloads folder. The installer needs Administrator privileges to run. You may see a User Account
Control dialog asking you to give permission to let the installer make changes to your system; choose Yes. If
you are having trouble, find the downloaded file in File Explorer, right-click on the installer icon, and choose
Run as Administrator from the context menu.
3. The installer presents you with a list of workloads, which are groups of related options for specific
development areas. Support for C++ is now part of optional workloads that aren't installed by default.
For C++, select the Desktop development with C++ workload and then choose Install.
4. When the installation completes, choose the Launch button to start Visual Studio.
The first time you run Visual Studio, you are asked to sign in with a Microsoft Account. If you don't have one,
you can create one for free. You must also choose a theme. Don't worry, you can change it later if you want
to.
It may take Visual Studio several minutes to get ready for use the first time you run it. Here's what it looks
like in a quick time-lapse:
Visual Studio starts much faster when you run it again.
5. When Visual Studio opens, check to see if the flag icon in the title bar is highlighted:
If it is highlighted, select it to open the Notifications window. If there are any updates available for Visual
Studio, we recommend you install them now. Once the installation is complete, restart Visual Studio.
When Visual Studio is running, you are ready to continue to the next step.
Next Steps
Create a C++ project
https://docs.microsoft.com/
Install C++ support in Visual Studio
9/24/2018 • 3 minutes to read • Edit Online
If you haven't downloaded and installed Visual Studio 2017 and the Visual C++ tools yet, here's how to get
started.
Prerequisites
A broadband internet connection. The Visual Studio installer can download several gigabytes of data.
A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 10 for the best
development experience. Make sure that the latest updates are applied to your system before you install
Visual Studio.
Enough free disk space. Visual Studio requires at least 7GB of disk space, and can take 50GB or more if
many common options are installed. We recommend you install it on your C: drive.
For details on the disk space and operating system requirements, see Visual Studio Product Family System
Requirements. The installer reports how much disk space is required for the options you select.
TIP
The Community edition is for individual developers, classroom learning, academic research, and open source
development. For other uses, install Visual Studio 2017 Professional or Visual Studio 2017 Enterprise.
2. Find the installer file you downloaded and run it. It may be displayed in your browser, or you may find it in
your Downloads folder. The installer needs Administrator privileges to run. You may see a User Account
Control dialog asking you to give permission to let the installer make changes to your system; choose Yes.
If you are having trouble, find the downloaded file in File Explorer, right-click on the installer icon, and
choose Run as Administrator from the context menu.
3. The installer presents you with a list of workloads, which are groups of related options for specific
development areas. Support for C++ is now part of optional workloads that aren't installed by default.
For C++, select the Desktop development with C++ workload and then choose Install.
4. When the installation completes, choose the Launch button to start Visual Studio.
The first time you run Visual Studio, you are asked to sign in with a Microsoft Account. If you don't have
one, you can create one for free. You must also choose a theme. Don't worry, you can change it later if you
want to.
It may take Visual Studio several minutes to get ready for use the first time you run it. Here's what it looks
like in a quick time-lapse:
Visual Studio starts much faster when you run it again.
5. When Visual Studio opens, check to see if the flag icon in the title bar is highlighted:
If it is highlighted, select it to open the Notifications window. If there are any updates available for Visual
Studio, we recommend you install them now. Once the installation is complete, restart Visual Studio.
When Visual Studio is running, you are ready to continue to the next step.
Next Steps
Create a C++ project
https://docs.microsoft.com/
Create a C++ console app project
9/24/2018 • 4 minutes to read • Edit Online
The usual starting point for a C++ programmer is a "Hello, world!" application that runs on the command line.
That's what you'll create in Visual Studio in this step.
Prerequisites
Have Visual Studio with the Desktop development with C++ workload installed and running on your
computer. If it's not installed yet, see Install C++ support in Visual Studio 2017.
2. In the New Project dialog, select Installed, Visual C++ if it isn't selected already, and then choose the
Empty Project template. In the Name field, enter HelloWorld. Choose OK to create the project.
Visual Studio creates a new, empty project, ready for you to specialize for the kind of app you want to create and
to add your source code files. You'll do that next.
I ran into a problem.
#include <iostream>
int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
When the code looks like this in the editor, you're ready to go on to the next step and build your app.
I ran into a problem.
Next Steps
Build and run a C++ project
Troubleshooting guide
Come here for solutions to common issues when you create your first C++ project.
Create your app project issues
If the New Project dialog doesn't show a Visual C++ entry under Installed, your copy of Visual Studio probably
doesn't have the Desktop development with C++ workload installed. You can run the installer right from the
New Project dialog. Choose the Open Visual Studio Installer link to start the installer again. If the User
Account Control dialog requests permissions, choose Yes. In the installer, make sure the Desktop
development with C++ workload is checked, and choose OK to update your Visual Studio installation.
If another project with the same name already exists, choose another name for your project, or delete the existing
project and try again. To delete an existing project, delete the solution folder (the folder that contains the
helloworld.sln file) in File Explorer.
Go back.
Make your project a console app issues
If you don't see Linker listed under Configuration Properties, choose Cancel to close the Property Pages
dialog and then make sure that the HelloWorld project is selected in Solution Explorer, not the solution or
another file or folder, before you try again.
The dropdown control does not appear in the SubSystem property edit box until you select the property. You can
select it by using the pointer, or you can press Tab to cycle through the dialog controls until SubSystem is
highlighted. Choose the dropdown control or press Alt+Down to open it.
Go back
Add a source code file issues
It's okay if you give the source code file a different name. However, don't add more than one source code file that
contains the same code to your project.
If you added the wrong kind of file to your project, for example, a header file, delete it and try again. To delete the
file, select it in Solution Explorer and press the Delete key.
Go back.
Add code to the source file issues
If you accidentally closed the source code file editor window, to open it again, double-click on HelloWorld.cpp in
the Solution Explorer window.
If red squiggles appear under anything in the source code editor, check that your code matches the example in
spelling, punctuation, and case. Case is significant in C++ code.
Go back.
https://docs.microsoft.com/
Build and run a C++ console app project
9/24/2018 • 3 minutes to read • Edit Online
When you've created a C++ console app project and entered your code, you can build and run it within Visual
Studio, and then run it as a stand-alone app from the command line.
Prerequisites
Have Visual Studio with the Desktop development with C++ workload installed and running on your
computer. If it's not installed yet, follow the steps in Install C++ support in Visual Studio.
Create a "Hello, World!" project and enter its source code. If you haven't done this yet, follow the steps in
Create a C++ console app project.
If Visual Studio looks like this, you're ready to build and run your app:
A console window opens and then runs your app. When you start a console app in Visual Studio, it runs
your code, then prints "Press any key to continue . . ." to give you a chance to see the output.
Congratulations! You've created your first "Hello, world!" console app in Visual Studio! Press a key to dismiss the
console window and return to Visual Studio.
I ran into a problem.
Next Steps
Once you've built and run this simple app, you're ready for more complex projects. See Using the Visual Studio
IDE for C++ Desktop Development for more detailed walkthroughs that explore the capabilities of Visual C++ in
Visual Studio.
Troubleshooting guide
Come here for solutions to common issues when you create your first C++ project.
Build and run your code in Visual Studio issues
If red squiggles appear under anything in the source code editor, the build may have errors or warnings. Check that
your code matches the example in spelling, punctuation, and case.
Go back.
Run your code in a command window issues
You can also navigate to the solution Debug folder at the command line to run your app. You can't run your app
from other directories without specifying the path to the app. However, you can copy your app to another directory
and run it from there.
If you don't see Copy as path in the shortcut menu, dismiss the menu, and then hold down the Shift key while you
open it again. This is just for convenience. You can also copy the path to the folder from the File Explorer search
bar, and paste it into the Run dialog, and then enter the name of your executable at the end. It's just a little more
typing, but it has the same result.
Go back.
https://docs.microsoft.com/
C++ conformance improvements in Visual Studio
2017 versions 15.0, 15.3, 15.5, 15.6, 15.7, 15.8
10/8/2018 • 47 minutes to read • Edit Online
With support for generalized constexpr and NSDMI for aggregates, the Microsoft Visual C++ compiler is now
complete for features added in the C++14 Standard. Note that the compiler still lacks a few features from the
C++11 and C++98 Standards. See Visual C++ Language Conformance for a table that shows the current state of
the compiler.
C++11
Expression SFINAE support in more libraries
The compiler continues to improve its support for expression SFINAE, which is required for template argument
deduction and substitution where decltype and constexpr expressions may appear as template parameters. For
more information, see Expression SFINAE improvements in Visual Studio 2017 RC.
C++ 14
NSDMI for Aggregates
An aggregate is an array or a class with no user-provided constructor, no private or protected non-static data
members, no base classes, and no virtual functions. Beginning in C++14 aggregates may contain member
initializers. For more information, see Member initializers and aggregates.
Extended constexpr
Expressions declared as constexpr are now allowed to contain certain kinds of declarations, if and switch
statements, loop statements, and mutation of objects whose lifetime began within the constexpr expression
evaluation. Also, there is no longer a requirement that a constexpr non-static member function be implicitly const.
For more information, see Relaxing constraints on constexpr functions.
C++17
Terse static_assert
the message parameter for static_assert is optional. For more information, see Extending static_assert, v2.
[[fallthrough]] attribute
In /std:c++17 mode, the [[fallthrough]] attribute can be used in the context of switch statements as a hint to the
compiler that the fall-through behavior is intended. This prevents the compiler from issuing warnings in such
cases. For more information, see Wording for [[fallthrough]] attribute.
Generalized range -based for loops
Range-based for loops no longer require that begin() and end() return objects of the same type. This enables
end() to return a sentinel as used by ranges in range-v3 and the completed-but-not-quite-published Ranges
Technical Specification. For more information, see Generalizing the Range-Based For Loop.
struct A {
template<typename T>
A(T, typename T::type = 0);
A(int);
};
struct B : A {
using A::A;
B(int n) = delete; // Error C2280
};
struct A {
template<typename T>
A(T, typename T::type = 0);
A(int);
};
struct B : A {
using A::A;
B(int n)
{
//do something
}
};
struct Derived;
struct Base {
friend struct Derived;
private:
Base() {}
};
In C++17, Derived is now considered an aggregate type; therefore, the initialization of Base via the private
default constructor happens directly as part of the extended aggregate initialization rule. Previously, the Base
private constructor was called via the Derived constructor and it succeeded because of the friend declaration.
The following example shows C++17 behavior in Visual Studio version 15.7 in /std:c++17 mode:
struct Derived;
struct Base {
friend struct Derived;
private:
Base() {}
};
The following example shows C++17 code in Visual Studio 15.7 in /std:c++17 mode:
Bug fixes in Visual Studio versions 15.0, 15.3, 15.5, 15.7, and 15.8
Copy-list-initialization
Visual Studio 2017 correctly raises compiler errors related to object creation using initializer lists that were not
caught in Visual Studio 2015 and could lead to crashes or undefined runtime behavior. As per N4594 13.3.1.7p1,
in copy-list-initialization, the compiler is required to consider an explicit constructor for overload resolution, but
must raise an error if that overload is actually chosen.
The following two examples compile in Visual Studio 2015 but not in Visual Studio 2017.
struct A
{
explicit A(int) {}
A(double) {}
};
int main()
{
A a1 = { 1 }; // error C3445: copy-list-initialization of 'A' cannot use an explicit constructor
const A& a2 = { 1 }; // error C2440: 'initializing': cannot convert from 'int' to 'const A &'
A a1{ 1 };
const A& a2{ 1 };
In Visual Studio 2015, the compiler erroneously treated copy-list-initialization in the same way as regular copy-
initialization; it considered only converting constructors for overload resolution. In the following example, Visual
Studio 2015 chooses MyInt(23) but Visual Studio 2017 correctly raises the error.
// From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1228
struct MyStore {
explicit MyStore(int initialCapacity);
};
struct MyInt {
MyInt(int i);
};
struct Printer {
void operator()(MyStore const& s);
void operator()(MyInt const& i);
};
void f() {
Printer p;
p({ 23 }); // C3066: there are multiple ways that an object of this type can be called with these
arguments
}
This example is similar to the previous one but raises a different error. It succeeds in Visual Studio 2015 and fails
in Visual Studio 2017 with C2668.
struct A {
explicit A(int) {}
};
struct B {
B(int) {}
};
int main()
{
f({ 1 }); // error C2668: 'f': ambiguous call to overloaded function
}
Deprecated typedefs
Visual Studio 2017 now issues the correct warning for deprecated typedefs that are declared in a class or struct.
The following example compiles without warnings in Visual Studio 2015 but produces C4996 in Visual Studio
2017.
struct A
{
// also for __declspec(deprecated)
[[deprecated]] typedef int inttype;
};
int main()
{
A::inttype a = 0; // C4996 'A::inttype': was declared deprecated
}
constexpr
Visual Studio 2017 correctly raises an error when the left-hand operand of a conditionally evaluating operation is
not valid in a constexpr context. The following code compiles in Visual Studio 2015 but not in Visual Studio 2017
(C3615 constexpr function 'f' cannot result in a constant expression):
template<int N>
struct array
{
int size() const { return N; }
};
To correct the error, either declare the array::size() function as constexpr or remove the constexpr qualifier
from f .
Class types passed to variadic functions
In Visual Studio 2017, classes or structs that are passed to a variadic function such as printf must be trivially
copyable. When passing such objects, the compiler simply makes a bitwise copy and does not call the constructor
or destructor.
#include <atomic>
#include <memory>
#include <stdio.h>
int main()
{
std::atomic<int> i(0);
printf("%i\n", i); // error C4839: non-standard use of class 'std::atomic<int>'
// as an argument to a variadic function.
// note: the constructor and destructor will not be called;
// a bitwise copy of the class will be passed as the argument
// error C2280: 'std::atomic<int>::atomic(const std::atomic<int> &)':
// attempting to reference a deleted function
struct S {
S(int i) : i(i) {}
S(const S& other) : i(other.i) {}
operator int() { return i; }
private:
int i;
} s(0);
printf("%i\n", s); // warning C4840 : non-portable use of class 'main::S'
// as an argument to a variadic function
}
To correct the error, you can call a member function that returns a trivially copyable type,
std::atomic<int> i(0);
printf("%i\n", i.load());
or else perform a static cast to convert the object before passing it:
For strings built and managed using CString, the provided operator LPCTSTR() should be used to cast a CString
object to the C pointer expected by the format string.
CString str1;
CString str2 = _T("hello!");
str1.Format(_T("%s"), static_cast<LPCTSTR>(str2));
struct S
{
S(int);
operator int();
};
#include <type_traits>
int main()
{
f(10); // C2672: No matching overloaded function found.
}
Expression-SFINAE
To support expression-SFINAE, the compiler now parses decltype arguments when the templates are declared
rather than instantiated. Consequently, if a non-dependent specialization is found in the decltype argument, it is
not deferred to instantiation-time and is processed immediately and any resulting errors are diagnosed at that
time.
The following example shows such a compiler error that is raised at the point of declaration:
#include <utility>
template <class T, class ReturnT, class... ArgsT>
class IsCallable
{
public:
struct BadType {};
value struct V
{
int i = 0; // error C3446: 'V::i': a default member initializer
// is not allowed for a member of a value class
};
using System.Reflection;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[DefaultMember("Value")]
public class Class1
{
public int Value
{
// using attribute on the return type triggers the compiler bug
[return: MarshalAs(UnmanagedType.I4)]
get;
}
}
[DefaultMember("Value")]
public class Class2
{
public int Value
{
get;
}
}
}
// code.cpp
#using "class1.dll"
In Visual Studio 2017, you can access both Value properties by their name:
#using "class1.dll"
void g()
{
decltype(S<int>::f<int>()) i; // this should fail
}
struct S;
enum E;
New compiler warning and runtime checks on native -to -managed marshaling
Calling from managed functions to native functions requires marshalling. The CLR performs the marshaling but it
doesn't understand C++ semantics. If you pass a native object by value, CLR either calls the object's copy-
constructor or uses BitBlt, which may cause undefined behavior at runtime.
Now the compiler emits a warning if it can know at compile time that a native object with deleted copy ctor is
passed between native and managed boundary by value. For those cases in which the compiler doesn't know at
compile time, it injects a runtime check so that the program calls std::terminate immediately when an ill-formed
marshalling occurs. In Visual Studio 2017 version 15.3, the following code produces warning C4606 "'A': passing
argument by value across native and managed boundary requires valid copy constructor. Otherwise the runtime
behavior is undefined".
class A
{
public:
A() : p_(new int) {}
~A() { delete p_; }
private:
int *p_;
};
#pragma unmanaged
void f(A a)
{
}
#pragma managed
int main()
{
f(A()); // This call from managed to native requires marshalling. The CLR doesn't understand C++ and uses
BitBlt, which results in a double-free later.
}
To fix the error, remove the #pragma managed directive to mark the caller as native and avoid marshalling.
Experimental API warning for WinRT
WinRT APIs that are released for experimentation and feedback are decorated with
Windows.Foundation.Metadata.ExperimentalAttribute . In Visual Studio 2017 version 15.3, the compiler produces
warning C4698 when it encounters the attribute. A few APIs in previous versions of the Windows SDK have
already been decorated with the attribute, and calls to these APIs now trigger this compiler warning. Newer
Windows SDKs have the attribute removed from all shipped types, but if you are using an older SDK, you'll need
to suppress these warnings for all calls to shipped types.
The following code produces warning C4698: "'Windows::Storage::IApplicationDataStatics2::GetForUserAsync' is
for evaluation purposes only and is subject to change or removal in future updates":
Windows::Storage::IApplicationDataStatics2::GetForUserAsync(); //C4698
#pragma warning(push)
#pragma warning(disable:4698)
Windows::Storage::IApplicationDataStatics2::GetForUserAsync();
#pragma warning(pop)
struct S {
template <typename T>
void f(T t);
};
template <typename T>
void S::f(T t) {}
#include <memory>
class B { };
class D : B { }; // C2243. should be public B { };
void f()
{
std::unique_ptr<B>(new D());
}
Default arguments are not allowed on out of line definitions of member functions
Default arguments are not allowed on out-of-line definitions of member functions in template classes The
compiler will issue a warning under /permissive, and a hard error under /permissive-.
In previous versions of Visual Studio, the following ill-formed code could potentially cause a runtime crash. Visual
Studio 2017 version 15.3 produces warning C5034: 'A<T>::f': an out-of-line definition of a member of a class
template cannot have default arguments:
struct A {
int arr[10];
};
To fix the code, either disable the warning with a pragma or change the code to not use offsetof :
#pragma warning(push)
#pragma warning(disable: 4841)
constexpr auto off = offsetof(A, arr[2]);
#pragma warning(pop)
#include <cstddef>
struct A {
int foo() { return 10; }
static constexpr int bar = 0;
};
This code is ill-formed and could potentially cause a crash at runtime. To fix the error, change the code to no
longer invoke undefined behavior. This is non-portable code that is disallowed by the C++ standard.
New warning on declspec attributes
In Visual Studio 2017 version 15.3, the compiler no longer ignores attributes if __declspec(...) is applied before
extern "C" linkage specification. Previously, the compiler would ignore the attribute, which could have runtime
implications. When the /Wall and /WX options are set, the following code produces "warning C4768: __declspec
attributes before linkage specification are ignored":
This warning is off by default in 15.3, but on by default in 15.5, and only impacts code compiled with /Wall /WX.
decltype and calls to deleted destructors
In previous versions of Visual Studio, the compiler did not detect when a call to a deleted destructor occurred in
the context of the expression associated with 'decltype'. In Visual Studio 2017 version 15.3, the following code
produces "error C2280: 'A<T>::~A(void)': attempting to reference a deleted function":
template<typename T>
struct A
{
~A() = delete;
};
template<typename T>
auto f() -> A<T>;
template<typename T>
auto g(T) -> decltype((f<T>()));
void h()
{
g(42);
}
struct A {};
template <typename> struct B {};
enum C { c1, c2, c3 };
int; // warning C4091 : '' : ignored on left of 'int' when no variable is declared
A; // warning C4091 : '' : ignored on left of 'main::A' when no variable is declared
B<int>; // warning C4091 : '' : ignored on left of 'B<int>' when no variable is declared
C; // warning C4091 : '' : ignored on left of 'C' when no variable is declared
To remove the warnings, simply comment-out or remove the empty declarations. In cases where the un-named
object is intended to have a side effect (such as RAII) it should be given a name.
The warning is excluded under /Wv:18 and is on by default under warning level W2.
std::is_convertible for array types
Previous versions of the compiler gave incorrect results for std::is_convertible for array types. This required
library writers to special-case the Microsoft Visual C++ compiler when using the std::is_convertible<...> type
trait. In the following example, the static asserts pass in earlier versions of Visual Studio but fail in Visual Studio
2017 version 15.3:
#include <type_traits>
static_assert(std::is_convertible<Array, Array>::value);
static_assert(std::is_convertible<const Array, const Array>::value, "");
static_assert(std::is_convertible<Array&, Array>::value, "");
static_assert(std::is_convertible<Array, Array&>::value, "");
std::is_convertible<From, To> is calculated by checking to see if an imaginary function definition is well formed:
#include <type_traits>
class PrivateDtor {
PrivateDtor(int) { }
private:
~PrivateDtor() { }
};
T obj(std::declval<Args>()...)
template<class T>
void f();
}
template<class T>
void f(T&, T&);
struct S {};
void f()
{
using N::f;
S s1, s2;
f(s1, s2); // C2668
}
To fix the code, remove the using N::f statement if you intended to call ::f() .
C2660: local function declarations and argument dependent lookup
Local function declarations hide the function declaration in the enclosing scope and disable argument dependent
lookup. However, previous versions of the compiler performed argument dependent lookup in this case,
potentially leading to the wrong overload being chosen and unexpected runtime behavior. Typically, the error is
due to an incorrect signature of the local function declaration. In the following example, Visual Studio 2017
version 15.3 correctly raises C2660 'f': function does not take 2 arguments:
struct S {};
void f(S, int);
void g()
{
void f(S); // C2660 'f': function does not take 2 arguments:
// or void f(S, int);
S s;
f(s, 0);
}
To fix the problem, either change the f(S) signature or remove it.
C5038: order of initialization in initializer lists
Class members are initialized in the order they are declared, not the order they appear in initializer lists. Previous
versions of the compiler did not warn when the order of the initializer list differed from the order of declaration.
This could lead to undefined runtime behavior if the intialization of one member depended on another member in
the list already being initialized. In the following example, Visual Studio 2017 version 15.3 (with /Wall) raises
"warning C5038: data member 'A::y' will be initialized after data member 'A::x'":
struct A
{
A(int a) : y(a), x(y) {} // Initialized in reverse, y reused
int x;
int y;
};
To fix the problem, arrange the intializer list to have the same order as the declarations. A similar warning is raised
when one or both initializers refer to base class members.
Note that the warning is off-by-default and only affects code compiled with /Wall.
Bug fixes and other behavior changes in Visual Studio 2017 version
15.5
Partial Ordering Change
The compiler now correctly rejects the following code and gives the correct error message:
template<typename... T>
int f(T* ...)
{
return 1;
}
template<typename T>
int f(const T&)
{
return 2;
}
int main()
{
int i = 0;
f(&i); // C2668
}
t161.cpp
t161.cpp(16): error C2668: 'f': ambiguous call to overloaded function
t161.cpp(8): note: could be 'int f<int*>(const T &)'
with
[
T=int*
]
t161.cpp(2): note: or 'int f<int>(int*)'
t161.cpp(16): note: while trying to match the argument list '(int*)'
The problem in the example above is that there are two differences in the types (const vs. non-const and pack vs.
non-pack). To eliminate the compiler error, remove one of the differences. This enables the compiler to
unambiguously order the functions.
template<typename... T>
int f(T* ...)
{
return 1;
}
template<typename T>
int f(T&)
{
return 2;
}
int main()
{
int i = 0;
f(&i);
}
Exception handlers
Handlers of reference to array or function type are never a match for any exception object. The compiler now
correctly honors this rule and raises a level 4 warning. It also no longer matches a handler of char* or wchar_t*
to a string literal when /Zc:strictStrings is used.
int main()
{
try {
throw "";
}
catch (int (&)[1]) {} // C4843 (This should always be dead code.)
catch (void (&)()) {} // C4843 (This should always be dead code.)
catch (char*) {} // This should not be a match under /Zc:strictStrings
}
warning C4843: 'int (&)[1]': An exception handler of reference to array or function type is unreachable, use
'int*' instead
warning C4843: 'void (__cdecl &)(void)': An exception handler of reference to array or function type is
unreachable, use 'void (__cdecl*)(void)' instead
#include <functional>
#include <iostream>
using namespace std;
int main() {
std::tr1::function<int (int, int)> f = std::plus<int>(); //C4996
cout << f(3, 5) << std::endl;
f = std::multiplies<int>();
cout << f(3, 5) << std::endl;
}
warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are
deprecated and will be REMOVED. You can define _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING to acknowledge that
you have received this warning.
#include <functional>
#include <iostream>
using namespace std;
int main() {
std::function<int (int, int)> f = std::plus<int>();
cout << f(3, 5) << std::endl;
f = std::multiplies<int>();
cout << f(3, 5) << std::endl;
}
#include <iterator>
#include <type_traits>
To fix the error, follow the instructions in the warning text, as demonstrated in the following code:
#include <iterator>
class MyIter {
public:
typedef std::random_access_iterator_tag iterator_category;
typedef int value_type;
typedef ptrdiff_t difference_type;
typedef int* pointer;
typedef int& reference;
#include <type_traits>
void f() {
char s[2] = {0}; // C4189. Either use the variable or remove it.
}
/* C only */
#pragma warning(disable:4001) //C4619
#pragma warning(disable:4179)
// single line comment
//* single line comment */
If the code does not need to be backwards compatible, you can avoid the warning by removing the C4001/C4179
suppression. If the code does need to be backward compatible, then suppress C4619 only.
/* C only */
#pragma warning(disable:4619)
#pragma warning(disable:4001)
#pragma warning(disable:4179)
To fix the error, place the linkage specification before the __declspec attribute:
This new warning C4768 is given on some Windows SDK headers that were shipped with Visual Studio 2017
15.3 or older (for example: version 10.0.15063.0, also known as RS2 SDK). However, later versions of Windows
SDK headers (specifically, ShlObj.h and ShlObj_core.h) have been fixed so that they do not produce this warning.
When you see this warning coming from Windows SDK headers, you can take these actions:
1. Switch to the latest Windows SDK that came with Visual Studio 2017 version 15.5 release.
2. Turn off the warning around the #include of the Windows SDK header statement:
If a header file contains a variable declared extern constexpr , it needs to be marked __declspec(selectany) in
order to correctly have its duplicate declarations combined:
#include <typeinfo>
struct S;
#include <type_traits>
To avoid the error, when using is_convertible you should compare pointer types because a non-pointer-type
comparison might fail if one type is abstract:
#include <type_traits>
struct A {
virtual void f() throw();
};
struct B : A {
virtual void f() { } // error C2694
};
To remove the errors while still using /std:c++17, either add the /Zc:noexceptTypes- switch to the command
line, or else update your code to use noexcept , as shown in the following example:
struct A {
virtual void f() noexcept;
};
struct B : A {
virtual void f() noexcept { }
};
Inline variables
Static constexpr data members are now implicitly inline, which means that their declaration within a class is now
their definition. Using an out-of-line definition for a static constexpr data member is redundant, and now
deprecated. In Visual Studio 2017 version 15.5 when the /std:c++17 switch is applied, the following code now
produces warning C5041 'size': out-of-line definition for constexpr static data member is not needed and is
deprecated in C++17:
struct X {
static constexpr int size = 3;
};
const int X::size; // C5041
struct A {
A& operator=(const A& other) { // No exception specification; this function may throw.
...
}
};
struct B : public A {
__declspec(nothrow) B& operator=(const B& other) = default;
};
int main()
{
B b1, b2;
b2 = b1; // error C2280
}
To correct this code, either remove __declspec(nothrow ) from the defaulted function, or remove = default and
provide a definition for the function along with any required exception handling:
struct A {
A& operator=(const A& other) {
// ...
}
};
struct B : public A {
B& operator=(const B& other) = default;
};
int main()
{
B b1, b2;
b2 = b1;
}
template <>
struct A<void(*)()>
{
static const bool value = true;
};
int main()
{
return g(&f) ? 0 : 1; // C2027
}
The following code succeeds under /std:c++17 because the compiler chooses the new partial specialization
A<void (*)() noexcept> :
template <>
struct A<void(*)()>
{
static const bool value = true;
};
template <>
struct A<void(*)() noexcept>
{
static const bool value = true;
};
int main()
{
return g(&f) ? 0 : 1; // OK
}
Bug fixes and other behavior changes in Visual Studio 2017 version
15.7
C++17 Default argument in the primary class template
This behavior change is a precondition for Template argument deduction for class templates - P0091R3, which is
planned to be fully supported in a later preview of Visual Studio 2017 version 15.7.
Previously, the compiler ignored the default argument in the primary class template.
template<typename T>
struct S {
void f(int = 0);
};
template<typename T>
void S<T>::f(int = 0) {} // Re-definition necessary
In /std:c++17 mode in Visual Studio 2017 version 15.7, the default argument is not ignored:
template<typename T>
struct S {
void f(int = 0);
};
template<typename T>
void S<T>::f(int) {} // Default argument is used
template<typename T>
struct B {
using type = T;
};
template<typename T>
struct D : B<T*> {
using type = B<T*>::type;
};
Visual Studio 2017 version 15.7, in /std:c++17 mode, requires the typename keyword in the using statement in
D. Without typename the compiler raises warning C4346: 'B<T*>::type': dependent name is not a type and error
C2061: syntax error: identifier 'type':
template<typename T>
struct B {
using type = T;
};
template<typename T>
struct D : B<T*> {
using type = typename B<T*>::type;
};
int main() {
f(); // warning: discarding return value
// of function with 'nodiscard'
}
template<typename T>
struct B {};
template<typename T>
struct D : B<T>
{
template<typename ...C>
D() : B() {} // C2614. Missing template arguments to B.
};
D<int> d;
#include <array>
struct X {
unsigned short a;
unsigned char b;
};
int main() {
constexpr std::array<X, 2> xs = {
{ 1, 2 },
{ 3, 4 }
};
return 0;
}
In Visual Studio 2017 version 15.7 update 3 and later, the previous example now raises C2078 too many
initializers. The following example shows how to fix the code. When initializing a std::array with nested brace-
init-lists, give the inner array a braced-list of its own:
#include <array>
struct X {
unsigned short a;
unsigned char b;
};
int main() {
constexpr std::array<X, 2> xs = {{ // note double braces
{ 1, 2 },
{ 3, 4 }
}}; // note double braces
return 0;
}
Bug fixes and behavior changes in Visual Studio 2017 version 15.8
The compiler changes in Visual Studio 2017 version 15.8 all fall under the category of bug fixes and behavior
changes, and are listed below:
typename on unqualified identifiers
In /permissive- mode, spurious typename keywords on unqualified identifiers in alias template definitions are no
longer accepted by the compiler. The following code now produces C7511 'T': 'typename' keyword must be
followed by a qualified name:
To fix the error, change to code to the following (with the attribute placed before the '=' of the alias definition):
namespace std {
template<typename T> class vector;
}
To fix the error, use an include directive rather than a forward declaration:
#include <vector>
class X {
public:
X(int, int);
X(int v) : X(v, 0) {}
};
struct Data {
int x;
};
int main()
{
switch (0) {
case MY_OFFSET(Data, x): return 0;
default: return 1;
}
}
struct Data {
int x;
};
int main()
{
switch (0) {
case offsetof(Data, x): return 0;
default: return 1;
}
}
template<typename... T>
class X : public T... { };
class S { };
int main()
{
X<const S> x;
}
template<typename T>
struct X : Base<T>
{
void foo()
{
Base<T>::foo<int>();
}
};
To fix the error, add the template keyword to the Base<T>::foo<int>(); statement, as shown in the following
example:
template<typename T> struct Base
{
template<class U> void foo() {}
};
template<typename T>
struct X : Base<T>
{
void foo()
{
// Add template keyword here:
Base<T>::template foo<int>();
}
};
See also
Visual C++ Language Conformance
Visual C++ Language Conformance
9/19/2018 • 13 minutes to read • Edit Online
This topic summarizes the ISO C++03, C++11, C++14, C++17, and Draft C++20 language standards
conformance of compiler features and Standard Library features for the C++ compiler in Visual Studio 2017 and
earlier versions. Each compiler and standard library feature name links to the ISO C++ Standard proposal paper
that describes the feature, if one is available at publication time. The Supported column lists the Visual Studio
version in which support for the feature first appeared.
For details on conformance improvements and other changes in Visual Studio 2017, see C++ conformance
improvements in Visual Studio 2017 and What's New for Visual C++ in Visual Studio 2017. For conformance
changes in earlier versions, see Visual C++ change history and Visual C++ What's New 2003 through 2015. For
current news from the C++ team, visit the Visual C++ team blog.
NOTE
There are no binary breaking changes between Visual Studio 2015 and Visual Studio 2017.
Compiler Features
FEATURE AREA
FEATURE AREA
P0734R0 Concepts No
P0463R1 endian No
P0053R7 <syncstream> No
P0753R2 osyncstream Manipulators
P0122R7 <span> No
P0550R2 remove_cvref No
P0653R2 to_address() No
P0754R2 <version> No
A group of papers listed together indicates that a feature was voted into the Standard, and then one or more
papers to improve or expand that feature were also voted in. These features are implemented together.
Supported values
No means not yet implemented.
Partial means the implementation in Visual Studio 2017 is incomplete. For more details, see the Notes section.
N/A means the proposal papers do not describe features. These papers altered the language of the standard, but
didn’t create any work for implementers. They’re listed here for completeness.
VS 2010 indicates features that are supported in Visual Studio 2010.
VS 2013 indicates features that are supported in Visual Studio 2013.
VS 2015 indicates features that are supported in Visual Studio 2015 RTM.
VS 2015.2 and VS 2015.3 indicate features that are supported in Visual Studio 2015 Update 2 and Visual Studio
2015 Update 3, respectively.
VS 2017 indicates features that are supported in Visual Studio 2017 RTM.
VS 2017 15.3 indicates features that are supported in Visual Studio 2017 version 15.3.
VS 2017 15.5 indicates features that are supported in Visual Studio 2017 version 15.5. VS 2017 15.7 indicates
features that are supported in Visual Studio 2017 version 15.7.
Notes
A In /std:c++14 mode, dynamic exception specifications remain unimplemented, and throw () is still treated as a
synonym for __declspec(nothrow ). In C++17, dynamic exception specifications were mostly removed by
P0003R5, leaving one vestige: throw () is deprecated and required to behave as a synonym for noexcept. In
/std:c++17 mode, MSVC now conforms to the Standard by giving throw () the same behavior as noexcept, i.e.
enforcement via termination. The compiler option /Zc:noexceptTypes- requests our old behavior of
__declspec(nothrow ). It’s likely that throw () will be removed in C++20. To help with migrating code in response to
these changes in the Standard and our implementation, new compiler warnings for exception specification issues
have been added under /std:c++17 and /permissive-.
B Supported in /permissive- mode in Visual Studio 2017 version 15.7. See Two-phase name lookup support
comes to MSVC for more information.
C The compiler’s support for Expression SFINAE has been sufficient for the Standard Library since Visual Studio
2015 Update 2. Supported in Visual Studio 2017 15.7 regardless of whether /permissive- mode is set. Some bugs
remain to be fixed. The “unique tag type” workaround is no longer necessary, and we’ve removed this
workaround from our STL implementation.
D The compiler’s support for C99 Preprocessor rules is incomplete in Visual Studio 2017. Variadic macros are
supported, but there are many bugs in the preprocessor’s behavior. We are overhauling the preprocessor, and will
experimentally ship those changes under the /permissive- mode soon.
E This is marked as Not Applicable because compilers are permitted, but not required, to support extended
integer types. Like GCC and Clang, we’ve chosen not to support them.
F Similarly, this is marked as Not Applicable because compilers are permitted, but not required, to implement this
optimization.
G Supported under /std:c++14 with a suppressible warning.
J Features that were not completed in Visual Studio 2015 are broken out elsewhere in this table.
K This is a completely new implementation, incompatible with the previous std::experimental version, necessitated
by symlink support, bug fixes, and changes in standard-required behavior. Currently, including <filesystem>
provides the new std::filesystem and the previous std::experimental::filesystem, and including
<experimental/filesystem> provides only the old experimental implementation. The experimental implementation
will be REMOVED in the next ABI-breaking release of the libraries.
L Supported by a compiler intrinsic.
14 These C++17/20 features are always enabled, even when /std:c++14 (the default) is specified. This is either
because the feature was implemented before the introduction of the /std options, or because conditional
implementation was undesirably complex.
17 These features are enabled by the /std:c++17 (or /std:c++latest) compiler option.
byte std::byte is enabled by /std:c++17 (or /std:c++latest), but because it can conflict with the Windows SDK
headers in some cases, it has a fine-grained opt-out macro. It can be disabled by defining _HAS_STD_BYTE as 0 .
C11 The Universal CRT implemented the parts of the C11 Standard Library that are required by C++17, with the
exception of C99 strftime() E/O alternative conversion specifiers, C11 fopen() exclusive mode, and C11
aligned_alloc() . The latter is unlikely to be implemented, because C11 specified aligned_alloc() in a way that's
incompatible with the Microsoft implementation of free() , namely, that free() must be able to handle highly
aligned allocations.
rem Features removed when the /std:c++17 (or /std:c++latest) compiler option is specified. These features have
opt-out macros: _HAS_AUTO_PTR_ETC , _HAS_FUNCTION_ALLOCATOR_SUPPORT , _HAS_OLD_IOSTREAMS_MEMBERS , and
_HAS_UNEXPECTED .
charconv from_chars() and to_chars() are available for integers. We’re currently working on floating-point
from_chars(), to be followed by floating-point to_chars().
parallel C++17’s parallel algorithms library is complete. Note that this doesn’t mean every algorithm is
parallelized in every case; the most important algorithms have been parallelized and execution policy signatures
are provided even where algorithms are not parallelized. Our STL implementation’s central internal header,
yvals.h, contains the following “Parallel Algorithms Notes”: C++ allows an implementation to implement parallel
algorithms as calls to the serial algorithms. This implementation parallelizes several common algorithm calls, but
not all.
The following algorithms are parallelized:
adjacent_difference, adjacent_find, all_of, any_of, count, count_if, equal, exclusive_scan, find, find_end,
find_first_of, find_if, for_each, for_each_n, inclusive_scan, mismatch, none_of, reduce, remove, remove_if, search,
search_n, sort, stable_sort, transform, transform_exclusive_scan, transform_inclusive_scan, transform_reduce.
The following are not presently parallelized:
No apparent parallelism performance improvement on target hardware; all algorithms which merely copy or
permute elements with no branches are typically memory bandwidth limited:
copy, copy_backward, copy_n, fill, fill_n, move, move_backward, remove, remove_if, replace, replace_if,
reverse, reverse_copy, rotate, rotate_copy, swap_ranges
Confusion over user parallelism requirements exists; likely in the above category anyway:
generate, generate_n
Effective parallelism suspected to be infeasible:
partial_sort, partial_sort_copy
Not yet evaluated; parallelism may be implemented in a future release and is suspected to be beneficial:
copy_if, includes, inplace_merge, is_heap, is_heap_until, is_partitioned, is_sorted, is_sorted_until,
lexicographical_compare, max_element, merge, min_element, minmax_element, nth_element,
partition_copy, remove_copy, remove_copy_if, replace_copy, replace_copy_if, set_difference,
set_intersection, set_symmetric_difference, set_union, stable_partition, unique, unique_copy
See also
C++ Language Reference
C++ Standard Library
C++ conformance improvements in Visual Studio 2017
What's New for Visual C++ in Visual Studio 2017
Visual C++ change history 2003 through 2015
Visual C++ What's New 2003 through 2015
Visual C++ team blog
Supported Platforms (Visual C++)
8/29/2018 • 2 minutes to read • Edit Online
Apps built by using Visual Studio can be targeted to various platforms, as follows.
Windows XP X* X*
Windows Vista X X
Windows 7 X X
Windows 8 X X X
Windows 8.1 X X X
Windows 10 X X X
Android ** X X X
iOS ** X X X
Linux *** X X X
* You can use the Windows XP platform toolset included in Visual Studio 2017, Visual Studio 2015, Visual Studio
2013, and Visual Studio 2012 Update 1 or later to build Windows XP and Windows Server 2003 projects. For
information on how to use this platform toolset, see Configuring Programs for Windows XP. For additional
information on changing the platform toolset, see How to: Modify the Target Framework and Platform Toolset.
** You can install the Mobile development with C++ workload in the Visual Studio 2017 installer (or the
optional Visual C++ for Cross Platform Mobile Development component in Visual Studio 2015 setup) to
target iOS or Android platforms. For instructions, see Install Visual C++ for Cross-Platform Mobile Development.
To build iOS code, you must have a Mac computer and meet other requirements. For a list of prerequisites and
installation instructions, see Install And Configure Tools to Build using iOS. You can build x86 or ARM code to
match the target hardware. Use x86 configurations to build for the iOS simulator, Microsoft Visual Studio Emulator
for Android, and some Android devices. Use ARM configurations to build for iOS devices and most Android
devices.
*** You can install the Linux development with C++ workload in the Visual Studio 2017 installer to target Linux
platforms. For instructions, see Download, Install and Setup the Linux Workload. This toolset compiles your
executable on the target machine, so you can build for any supported architecture.
For information about how to set the target platform configuration, see How to: Configure Visual C++ Projects to
Target 64-Bit, x64 Platforms.
See also
Visual C++ Tools and Features in Visual Studio Editions
Getting Started
C Language Reference
9/18/2018 • 2 minutes to read • Edit Online
The C Language Reference describes the C programming language as implemented in Microsoft C. The book's
organization is based on the ANSI C standard (sometimes referred to as C89) with additional material on the
Microsoft extensions to the ANSI C standard.
Organization of the C Language Reference
For additional reference material on C++ and the preprocessor, see:
C++ Language Reference
Preprocessor Reference
Compiler and linker options are documented in the C/C++ Building Reference.
See Also
C++ Language Reference
C++ Language Reference
9/19/2018 • 2 minutes to read • Edit Online
This reference explains the C++ programming language as implemented in Microsoft Visual C++. The
organization is based on The Annotated C++ Reference Manual by Margaret Ellis and Bjarne Stroustrup and on
the ANSI/ISO C++ International Standard (ISO/IEC FDIS 14882). Microsoft-specific implementations of C++
language features are included.
For an overview of Modern C++ programming practices, see Welcome Back to C++.
See the following tables to quickly find a keyword or operator:
C++ Keywords
C++ Operators
In This Section
Lexical Conventions
Fundamental lexical elements of a C++ program: tokens, comments, operators, keywords, punctuators, literals.
Also, file translation, operator precedence/associativity.
Basic Concepts
Scope, linkage, program startup and termination, storage classes, and types.
Standard Conversions
Type conversions between built-in, or "fundamental," types. Also, arithmetic conversions and conversions among
pointer, reference, and pointer-to-member types.
Operators, Precedence and Associativity
The operators in C++.
Expressions
Types of expressions, semantics of expressions, reference topics on operators, casting and casting operators, run-
time type information.
Lambda Expressions
A programming technique that implicitly defines a function object class and constructs a function object of that
class type.
Statements
Expression, null, compound, selection, iteration, jump, and declaration statements.
Declarations and Definitions
Storage-class specifiers, function definitions, initializations, enumerations, class, struct, and union declarations,
and typedef declarations. Also, inline functions, const keyword, namespaces.
Classes, Structures, and Unions
Introduction to classes, structures, and unions. Also, member functions, special member functions, data members,
bit fields, this pointer, nested classes.
Derived Classes
Single and multiple inheritance, virtual functions, multiple base classes, abstract classes, scope rules. Also, the
__super and __interface keywords.
Member-Access Control
Controlling access to class members: public, private, and protected keywords. Friend functions and classes.
Overloading
Overloaded operators, rules for operator overloading.
Exception Handling
C++ exception handling, structured exception handling (SEH), keywords used in writing exception handling
statements.
Assertion and User-Supplied Messages
#error directive, the static_assert keyword, the assert macro.
Templates
Template specifications, function templates, class templates, typename keyword, templates vs. macros, templates
and smart pointers.
Event Handling
Declaring events and event handlers.
Microsoft-Specific Modifiers
Modifiers specific to Microsoft C++. Memory addressing, calling conventions, naked functions, extended storage-
class attributes (__declspec), __w64.
Inline Assembler
Using assembly language and C++ in __asm blocks.
Compiler COM Support
A reference to Microsoft-specific classes and global functions used to support COM types.
Microsoft Extensions
Microsoft extensions to C++.
Nonstandard Behavior
Information about nonstandard behavior of the Visual C++ compiler.
Welcome Back to C++
An overview of modern C++ programming practices for writing safe, correct and efficient programs.
Related Sections
Component Extensions for Runtime Platforms
Reference material on using Visual C++ to target the common language runtime.
C/C++ Building Reference
Compiler options, linker options, and other build tools.
C/C++ Preprocessor Reference
Reference material on pragmas, preprocessor directives, predefined macros, and the preprocessor.
Visual C++ Libraries
A list of links to the reference start pages for the various Visual C++ libraries.
See also
C Language Reference
C/C++ Preprocessor Reference
9/19/2018 • 2 minutes to read • Edit Online
The C/C++ Preprocessor Reference explains the preprocessor as it is implemented in Microsoft C/C++. The
preprocessor performs preliminary operations on C and C++ files before they are passed to the compiler. You can
use the preprocessor to conditionally compile code, insert files, specify compile-time error messages, and apply
machine-specific rules to sections of code.
In This Section
Preprocessor Directives
Describes directives, typically used to make source programs easy to change and easy to compile in different
execution environments.
Preprocessor Operators
Discusses the four preprocessor-specific operators used in the context of the #define directive.
Predefined Macros
Discusses predefined macros as specified by ANSI and Microsoft C++.
Pragmas
Discusses pragmas, which offer a way for each compiler to offer machine- and operating system-specific features
while retaining overall compatibility with the C and C++ languages.
Related Sections
C++ Language Reference
Provides reference material for the Microsoft implementation of the C++ language.
C Language Reference
Provides reference material for the Microsoft implementation of the C language.
Building a C/C++ Program
Provides links to topics discussing compiler and linker options.
Creating and Managing Visual C++ Projects
Describes the user interface in Visual Studio that enables you to specify the directories that the project system will
search to locate files for your C++ project.
C Run-Time Library Reference
9/19/2018 • 2 minutes to read • Edit Online
The Microsoft run-time library provides routines for programming for the Microsoft Windows operating system.
These routines automate many common programming tasks that are not provided by the C and C++ languages.
Sample programs are included in the individual reference topics for most routines in the library.
In This Section
C Run-Time Libraries
Discusses the .lib files that comprise the C run-time libraries.
Universal C runtime routines by category
Provides links to the run-time library by category.
Global Variables and Standard Types
Provides links to the global variables and standard types provided by the run-time library.
Global Constants
Provides links to the global constants defined by the run-time library.
Alphabetical Function Reference
Provides a table of contents entry point into an alphabetical listing of all C run-time library functions.
Generic-Text Mappings
Provides links to the generic-text mappings defined in Tchar.h.
Language and Country/Region Strings
Describes how to use the setlocale function to set the language and Country/Region strings.
Related Sections
Debug Routines
Provides links to the debug versions of the run-time library routines.
Run-Time Error Checking
Provides links to functions that support run-time error checks.
DLLs and Visual C++ run-time library behavior
Discusses the entry point and startup code used for a DLL.
Debugging
Provides links to using the Visual Studio debugger to correct logic errors in your application or stored procedures.
C++ Standard Library Reference
9/19/2018 • 2 minutes to read • Edit Online
A C++ program can call on a large number of functions from this conforming implementation of the C++
Standard Library. These functions perform essential services such as input and output and provide efficient
implementations of frequently used operations.
For more information about Visual C++ run-time libraries, see CRT Library Features.
In This Section
C++ Standard Library Overview
Provides an overview of the Microsoft implementation of the C++ Standard Library.
iostream Programming
Provides an overview of iostream programming.
Header Files Reference
Provides links to reference topics discussing the C++ Standard Library header files, with code examples.
Overview of Windows Programming in C++
9/4/2018 • 7 minutes to read • Edit Online
You can use Visual C++ to write many kinds of programs that run on a Windows PC (x86, x64 or ARM ), on a
Windows server, in the cloud, or on Xbox. Well-written C++ programs have these qualities:
efficient in memory requirements
economical in power consumption
able to take full advantage of multicore and many-core devices
able to do general computing on the graphics processing unit (GPGPU )
able to take advantage of other recent advances in hardware.
There are several broad categories of Windows apps that you can develop with Visual C++. These categories have
different programming models, or app models, which have been introduced over the years. Each model uses
different libraries and APIs to provide access to the platform and create user interfaces such as windows and dialog
boxes. The C++ standard library as well as third-party libraries can be used in any of these categories, with a few
restrictions for UWP.
Windows Universal apps. The third category of Windows apps was introduced with Windows 8, and support
for this category of apps continues in Windows 10. These apps are frequently referred to as just "Windows
apps" and they include desktop and mobile apps that target a variety of devices. You can write these apps in
C++/CX, a dialect of C++ that includes support for Windows Runtime development, or in standard C++ with
COM using the Windows Runtime Library (WRL ). These apps were originally designed to run full-screen,
although in Windows 10 users have the option of running them in a desktop window. These apps are touch-
oriented, but it is easy to use the mouse to operate if users prefer or if a touch screen is not available. These
apps are distributed from the Microsoft Store, a fact which led to them being called "Store" apps.
UWP apps are able to run on all Windows 10 devices such as tablets and mobile phones, as well as on the desktop.
On the desktop, they are able to run as a desktop window, instead of always running full-screen. These apps can
also run on the Xbox, and on future devices. UWP apps run on the Windows Runtime, which provides user
interface elements, services, and an interface to the diverse hardware devices that are supported on Windows.
You can write UWP apps in C++/CX, a dialect of C++, you can use the C++/WinRT libraryfor some scenarios.
UWP apps compile to native code and have a XAML user interface, or use DirectX. Windows Runtime components
that are written in native code that UWP apps written in other languages can consume. For more information, see
Create a Universal Windows Platform app in C++, Create your first UWP game using DirectX, and Creating
Windows Runtime components in C++.
This category also includes using C++ for core components and computational code in the context of server and
cloud programming. Sometimes the performance-intensive code at the core of a server or cloud application is
written in C++ to maximize performance. You can compile such code into a DLL and use it from C# or Visual Basic.
.NET Framework applications. Most .NET Framework applications are written in C# or Visual Basic, but you
can also C++/CLI (the /clr compiler option in Visual C++). We recommend using C++/CLI for a minimal
interop layer in a larger application that includes managed and native code.
TIP
For Windows 10, you can use the Desktop App Converter to package your existing desktop application for deployment
through the Microsoft Store. For more information, see Using Visual C++ Runtime in Centennial project and Bring your
desktop app to the Universal Windows Platform (UWP) with the Desktop Bridge.
For Universal Windows Platform samples, see Windows Universal Samples on GitHub
If you have an existing Windows 8.1 project and want to port it to Windows 10, see Porting to the Universal
Windows Platform. If you have existing classic Win32 desktop libraries and code that you want to integrate into a
UWP app, see How to: Use Existing C++ Code in a Universal Windows Platform App.
For more information on UWP in general, see What's a Universal Windows Platform (UWP ) app?.
For more information on all of these concepts, see Guide to Windows Universal Apps.
Games
DirectX games can run on the PC or Xbox. For more information, see DirectX Developer Center.
SDKs, libraries, and header files
Visual C++ includes the C Runtime Library (CRT), the C++ Standard Library, and other Microsoft-specific libraries.
The include folders that contain header files for these libraries are located either in the Visual Studio installation
directory under the \VC\ folder, or in the case of the CRT, in the Windows SDK installation folder.
You can use the Vcpkg package manager to conveniently install hundreds of third-party open-source libraries for
Windows.
The Microsoft libraries include:
Microsoft Foundation Classes (MFC ): An object-oriented framework for creating traditional Windows
programs—especially enterprise applications—that have rich user interfaces that feature buttons, list boxes,
tree views, and other controls. For more information, see MFC Desktop Applications.
Active Template Library (ATL ): A powerful helper library for creating COM components. For more
information, see ATL COM Desktop Components.
C++ AMP (C++ Accelerated Massive Parallelism): A library that enables high-performance general
computational work on the GPU. For more information, see C++ AMP (C++ Accelerated Massive
Parallelism).
Concurrency Runtime: A library that simplifies the work of parallel and asynchronous programming for
multicore and many-core devices. For more information, see Concurrency Runtime.
Many Windows programming scenarios also require the Windows SDK, which includes the header files that
enable access to the Windows operating system components. By default, Visual Studio installs the Windows SDK
as a component of the C++ Desktop workload, which enables development of Universal Windows apps. To
develop UWP apps, you need the Windows 10 version of the Windows SDK. For information, see Windows 10
SDK. (For more information about the Windows SDKs for earlier versions of Windows, see the Windows SDK
archive).
Program Files (x86)\Windows Kits is the default location for all versions of the Windows SDK that you have
installed.
Other platforms such as Xbox and Azure have their own SDKs that you may have to install. For more information,
see the DirectX Developer Center and the Azure Developer Center.
Development Tools
Visual Studio includes a powerful debugger for native code, static analysis tools, graphics debugging tools, a full-
featured code editor, support for unit tests, and many other tools and utilities. For more information, see Get
started developing with Visual Studio, and IDE and Development Tools.
Related Articles
TITLE DESCRIPTION
You can use the Visual Studio IDE in Windows to create, edit and debug C++ projects that execute on a Linux
physical computer, virtual machine, or the Windows Subsystem for Linux. For any of these scenarios, first install
the Linux development with C++ workload.
2. If you use CMake or you are targeting IoT or embedded platforms, go to the Installation details pane on
the right, under Linux development with C++, expand Optional Components and choose the
components you need.
3. Click Modify to continue with the installation.
Linux setup
The target Linux computer must have openssh-server, g++, gdb, and gdbserver installed, and the ssh daemon
must be running. zip is required for automatic syncing of remote headers with your local machine for Intellisense
support. If these applications are not already present, you can install them as follows:
1. At a shell prompt on your Linux computer, run:
sudo apt-get install openssh-server g++ gdb gdbserver zip
You may be prompted for your root password due to the sudo command. If so, enter it and continue. Once
complete, these services and tools will be installed.
2. Ensure the ssh service is running on your Linux computer by running:
sudo service ssh start
This will start the service and run it in the background, ready to accept connections.
.NET Programming with C++/CLI (Visual C++)
9/20/2018 • 2 minutes to read • Edit Online
Visual Studio 2015: By default, CLR projects created with Visual Studio 2015 target .NET Framework 4.5.2. To
target .NET Framework 4.6 when you create a new project, in the New Project dialog, change the target
framework in the dropdown at the top middle of the dialog. To change the target framework for an existing
project, close the project, edit the project file (.vcxproj), and change the value of the Target Framework Version to
4.6. Next time you open the project, the settings will take effect.
Visual Studio 2017: In Visual Studio 2017, the default framework is 4.6.1 and the Framework version selector is
at the bottom of the New Project Dialog. C++/CLI itself is not installed by default. To install the component,
open the Visual Studio Installer and choose the C++/CLI component under Visual C++.
In This Section
C++/CLI Tasks
Native and .NET Interoperability
C++/CLI Migration Primer
Pure and Verifiable Code (C++/CLI)
Regular Expressions (C++/CLI)
File Handling and I/O (C++/CLI)
Graphics Operations (C++/CLI)
Windows Operations (C++/CLI)
Data Access Using ADO.NET (C++/CLI)
Interoperability with Other .NET Languages (C++/CLI)
Serialization (C++/CLI)
Managed Types (C++/CLI)
Reflection (C++/CLI)
Strong Name Assemblies (Assembly Signing) (C++/CLI)
Debug Class (C++/CLI)
STL/CLR Library Reference
C++ Support Library
Exceptions in C++/CLI
Boxing (C++/CLI)
See Also
Native and .NET Interoperability
Cloud and Web Programming in Visual C++
9/4/2018 • 2 minutes to read • Edit Online
In C++, you have several options for connecting to the web and the cloud.
See also
Visual C++
Networks and web services
Parallel Programming in Visual C++
9/19/2018 • 2 minutes to read • Edit Online
Visual C++ provides the following technologies to help you create multi-threaded and parallel programs that take
advantage of multiple cores and use the GPU for general purpose programming.
Related Articles
TITLE DESCRIPTION
Concurrency Runtime Classes that simplify the writing of programs that use data
parallelism or task parallelism.
C++ AMP (C++ Accelerated Massive Parallelism) Classes that enable the use of modern graphics processors for
general purpose programming.
Multithreading Support for Older Code (Visual C++) Older technologies that may be useful in older applications.
For new apps, use the Concurrency Runtime or C++ AMP.
Virtually all database products, SQL and NoSQL, provide an interface for native C++ applications. The industry
standard interface is ODBC which is supported by all major SQL database products and many NoSQL products.
For non-Microsoft products, consult the vendor for more information. Third-party libraries with various license
terms are also available.
Since 2011 Microsoft has aligned on ODBC as the standard for native applications to connecting to Microsoft SQL
Server databases, both on-premises and in the cloud. For more information, see Data Access Programming (MFC -
ATL ). C++/CLI libraries can use either the native ODBC drivers or ADO.NET. For more information, see Data
Access Using ADO.NET (C++/CLI) and Accessing data in Visual Studio.
In This Section
Data Access Programming (MFC/ATL )
Describes legacy data access programming with Visual C++, where the preferred way is to use one of the class
libraries such as the Active Template Class Library (ATL ) or Microsoft Foundation Class (MFC ) Library, which
simplify working with the database APIs.
Open Database Connectivity (ODBC )
The Microsoft Foundation Classes (MFC ) library supplies classes for programming with Open Database
Connectivity (ODBC ).
OLE DB Programming
A mostly legacy interface which is still required in some scenarios, specifically when you are programming against
linked servers.
Related Topics
Connect to SQL Database using C and C++
Connect to Azure SQL Database from C or C++ applications.
Microsoft Azure Storage Client Library for C++
Azure Storage is a cloud storage solution for modern applications that rely on durability, availability, and scalability
to meet the needs of their customers. Connect to Azure Storage from C++ by using the Azure Storage Client
Library for C++.
ODBC Driver 13.1 for SQL Server - Windows Released
The latest ODBC driver provides robust data access to Microsoft SQL Server 2016 Microsoft Azure SQL Database
for C/C++ based applications. Provides support for features including always encrypted, Azure Active Directory,
and AlwaysOn Availability Groups. Also available for MacOS and Linux.
SQL Server Native Client
SQL Server Native Client is a stand-alone data access application programming interface (API), used for both OLE
DB and ODBC, that supports SQL Server 2005 through SQL Server 2014. New applications should use the
ODBC Driver 13.1 for SQL Server.
Microsoft Azure C and C++ Developer Center
Azure makes it easy to build C++ applications with increased flexibility, scalability and reliability using tools you
love.
How to use Blob Storage from C++
Azure Blob storage is a service that stores unstructured data in the cloud as objects/blobs. Blob storage can store
any type of text or binary data, such as a document, media file, or application installer. Blob storage is also referred
to as object storage.
ODBC Programmer's Reference
The ODBC interface is designed for use with the C programming language. Use of the ODBC interface spans three
areas: SQL statements, ODBC function calls, and C programming.
See Also
Visual C++
Text and Strings in Visual C++
9/19/2018 • 2 minutes to read • Edit Online
An important aspect of developing applications for international markets is the adequate representation of local
character sets. The ASCII character set defines characters in the range 0x00 to 0x7F. There are other character sets,
primarily European, that define the characters within the range 0x00 to 0x7F identically to the ASCII character set
and also define an extended character set from 0x80 to 0xFF. Thus, an 8-bit, single-byte-character set (SBCS ) is
sufficient to represent the ASCII character set, as well as the character sets for many European languages.
However, some non-European character sets, such as Japanese Kanji, include many more characters than a single-
byte coding scheme can represent, and therefore require multibyte-character set (MBCS ) encoding.
In This Section
Unicode and MBCS
Discusses Visual C++ support for Unicode and MBCS programming.
Support for Unicode
Describes Unicode, a specification for supporting all character sets, including character sets that cannot be
represented in a single byte.
Support for Multibyte Character Sets (MBCS )
Discusses MBCS, an alternative to Unicode for supporting character sets, like Japanese and Chinese, that cannot
be represented in a single byte.
Generic-Text Mappings in Tchar.h
Provides Microsoft-specific generic-text mappings for many data types, routines, and other objects.
How to: Convert Between Various String Types
Demonstrates how to convert various Visual C++ string types into other strings.
Related Sections
Internationalization
Discusses international support in the C run-time library.
International Samples
Provides links to samples demonstrating internationalization in Visual C++.
Language and Country/Region Strings
Provides the language and country/region strings in the C run-time library.
vcpkg: A C++ package manager for Windows, Linux
and MacOS
10/5/2018 • 9 minutes to read • Edit Online
vcpkg is a command-line package manager that greatly simplifies the acquisition and installation of third-party
libraries on Windows, Linux and MacOS. If your project uses third-party libraries, we recommend that you use
vcpkg to install them. vcpkg supports both open-source and proprietary libraries. All libraries in the vcpkg
Windows catalog have been tested for compatibility with Visual Studio 2015 and Visual Studio 2017. As of May
2018 there are over 900 libraries in the Windows catalog and over 350 in the Linux/MacOS catalog. The C++
community is adding more libraries to both catalogs on an ongoing basis.
Installation
Clone the vcpkg repo from GitHub: https://github.com/Microsoft/vcpkg. You can download to any folder location
you prefer.
Run the bootstrapper in the root folder:
bootstrap-vcpkg.bat (Windows)
./bootstrap-vcpkg.sh (Linux, MacOS )
For CMAKE projects, use CMAKE_TOOLCHAIN_FILE to make libraries available with find_package() . For
example:
Per project
If you need to use a specific version of a library that is different from the version in your active vcpkg instance,
follow these steps:
1. Make a new clone of vcpkg
2. Modify the portfile for the library to obtain the version you need
3. Run vcpkg install <library>.
4. Use vcpkg integrate project to create a NuGet package that references that library on a per-project basis.
Upgrade Options
--no-dry-run Perform the upgrade; when not specified, the command only lists the out-of-date packages.
--keep-going Continue installing packages even if one fails.
--triplet <t> Set the default triplet for unqualified packages.
--vcpkg-root <path> Specify the vcpkg directory to use instead of current directory or tool directory.
Upgrade example
The following example shows how to upgrade only specified libraries. Note that vcpgk automatically pulls in
dependencies as necessary.
Remove a library
Type vcpkg remove to remove an installed library. If any other libraries depend on it, you are asked to rerun the
command with --recurse, which causes all downstream libraries to be removed.
Customize vcpkg
You can modify your clone of vcpkg in any way you like. You can create multiple vcpkg clones and modify the
portfiles in each one to obtain specific versions of libraries or specify command-line parameters. For example, in
an enterprise, one group of developers might be working on software that has one set of dependencies, and
another group might have a different set. You can set up two clones of vcpkg, and modify each one to download
the versions of the libraries and the compilation switches, etc, according to your needs.
Uninstall vcpkg
Just delete the directory.
Command-line reference
COMMAND DESCRIPTION
vcpkg hash <file> [alg] Hash a file by specific algorithm, default SHA512
vcpkg integrate install Make installed packages available user-wide. Requires admin
privileges on first use
vcpkg edit <pkg> Open up a port for editing (uses %EDITOR%, default 'code')
Options
OPTION DESCRIPTION
As part of the Visual Studio Integrated Development Environment (IDE ), Microsoft Visual C++ (MSVC ) shares
many windows and tools in common with other languages. Many of those, including Solution Explorer, the code
editor, and the debugger, are documented under Visual Studio IDE. Often, a shared tool or window has a slightly
different set of features for C++ than for the .NET languages or JavaScript. A few windows or tools are only
available in Visual Studio Professional or Visual Studio Enterprise editions.
In addition to shared tools in the Visual Studio IDE, MSVC has several tools specifically for native code
development. These tools are also listed in this article. For a list of which tools are available in each edition of
Visual Studio, see Visual C++ Tools and Features in Visual Studio Editions.
Create projects
A project is basically a set of source code files and resources such as images or data files that are built into an
executable file.
Visual Studio 2015 provides support for MSBuild projects. You can download Visual Studio extensions for other
build systems such as Qt or CMake.
Visual Studio 2017 provides support for any build system or custom build tools that you wish to use, with full
support for IntelliSense, browsing and debugging:
MSBuild is the native build system for Visual Studio. When you select File > New > Project from the
main menu, you see many kinds of MSBuild project templates that get you started quickly developing
different kinds of C++ applications.
In general, you should use these templates for new projects unless you have a specific reason to use CMake
or another project system. Some projects have a wizard that guides you step-by-step through the process
of creating a new project. For more information, see Creating and managing MSBuild-based projects.
CMake is a cross-platform build system that is integrated into the Visual Studio IDE when you install the
Desktop development with C++ workload. For more information, see CMake projects in Visual C++.
Any other C++ build system, including a loose collection of files, is supported via the Open Folder feature. You
create simple JSON files to invoke your build program and configure debugging sessions. For more
information, see Open Folder projects in Visual C++.
For more information about Git integration with repos in Azure, see Share your code with Visual Studio 2017 and
Azure Repos Git. For information about about Git integration with GitHub, see GitHub Extension for Visual Studio.
For more information about designing a user interface for a Universal Windows Platform app, see Design and UI.
For more information about creating a user interface for an MFC application, see MFC Desktop Applications. For
information about Win32 Windows programs, see Windows Desktop Applications.
Write code
After you create a project, all the project files are displayed in the Solution Explorer window. (A solution is a
logical container for one or more related projects.) When you click on a .h or .cpp file in Solution Explorer, the file
opens up in the code editor.
The code editor is a specialized word processor for C++ source code. It color-codes language keywords, method
and variable names, and other elements of your code to make the code more readable and easier to understand.
For more information, see Writing and refactoring code.
Debug
You can start debugging by pressing F5. Execution pauses on any breakpoints you have set. You can also step
through code one line at a time, view the values of variables or registers, and even in some cases make changes in
code and continue debugging without re-compiling. The following illustration shows a debugging session in which
execution is stopped on a breakpoint. The values of the data structure members are visible in the Watch Window.
Test
Visual Studio includes unit test frameworks for both native C++ and C++/CLI. Boost.Test, Google Test, and CTest
are also supported. Run your tests from the Test Explorer window:
For more information, see Verifying Code by Using Unit Tests and Write unit tests for C/C++ in Visual Studio.
Analyze
Visual Studio includes static code analysis tools that can detect potential problems in your source code. These tools
include an implementation of the C++ Core Guidelines rules checkers. For more information, see Code analysis
for C/C++ overview.
Related Articles
Visual C++ Tools and Features in Visual Studio Editions Shows which features are available in the various editions of
Visual Studio.
Creating and managing MSBuild-based projects Provides an overview of C++ MSBuild-based projects in
Visual Studio and links to other articles that explain how to
create and manage them.
CMake projects in Visual C++. Describes how to build CMake or other non-MSBuild projects
in Visual C++.
Visual C++ Porting and Upgrading Guide Detailed information about how to upgrade C++ applications
that were created in earlier versions of Visual Studio, and also
how to migrate applications that were created by using tools
other than Visual Studio.
Visual C++ Describes key features of Visual C++ in Visual Studio and links
to the rest of the Visual C++ documentation.
Building C/C++ Programs
9/19/2018 • 2 minutes to read • Edit Online
You can build Visual C++ projects either in Visual Studio or on the command line. The Visual Studio IDE uses
MSBuild to build projects and solutions. On the command line, you can use the C/C++ compiler (cl.exe) and linker
(link.exe) to build simple projects. To build more complex projects on the command line, you can use MSBuild or
NMAKE. For an overview about how to use Visual Studio to build projects and solutions, see Compiling and
Building.
In This Section
Building C++ Projects in Visual Studio
Discusses how to use the Visual Studio IDE to build your C/C++ project.
Build C/C++ code on the command line
Discusses how to use the C/C++ command-line compiler and build tools that are included in Visual Studio.
Building C/C++ Isolated Applications and Side-by-side Assemblies
Describes the deployment model for Windows Desktop applications, based on the idea of isolated applications and
side-by-side assemblies.
C/C++ Building Reference
Provides links to reference articles about program building in C++, compiler and linker options, and various build
tools.
Configure Visual C++ for 64-bit, x64 targets
Describes how to configure both Visual Studio and the command line to use the 64-bit toolset and how to target
64-bit architectures, and discusses common migration issues when code is moved to 64-bit architectures.
Configure Visual C++ for ARM processors
Describes the conventions used by ARM processors, and discusses common migration issues when code is moved
to ARM architectures.
Configuring Programs for Windows XP
Describes how to set the Platform Toolset to target Windows XP development.
Related Sections
Compiling and Building
Describes the Visual Studio build system and tools.
Visual C++ Porting and Upgrading Guide
9/20/2018 • 6 minutes to read • Edit Online
This topic provides a guide for upgrading Visual C++ code. This includes getting the code to compile and run
correctly on a newer release of the tools, as well as taking advantage of new language and Visual Studio features.
This topic also includes information about migrating legacy apps to more modern platforms.
Related Topics
TITLE DESCRIPTION
Upgrading Projects from Earlier Versions of Visual C++ Discusses how to use projects created in earlier versions of
Visual C++.
What's New for The C++ compiler in Visual Studio 2017 RC Changes in the IDE and tools from Visual Studio 2015 to
Visual Studio 2017
TITLE DESCRIPTION
C++ conformance improvements in Visual Studio 2017 Standards conformance improvements from Visual Studio
2015 to Visual Studio 2017
Visual C++ change history 2003 - 2015 A list of all the changes in the Visual C++ libraries and build
tools from Visual Studio 2003 through 2015 that might
require changes in your code.
Visual C++ What's New 2003 through 2015 All the "what's new" information for Visual C++ from Visual
Studio 2003 through Visual Studio 2015.
Porting 3rd-party libraries How to use the vcpkg command line tool to port older open-
source libraries to versions compiled with more recent Visual
C++ toolsets.
Porting and Upgrading: Examples and Case Studies For this section, we ported and upgrades several samples and
applications and discussed the experiences and results. You
might find that reading these gives you a sense of what is
involved in the porting and upgrading process. Throughout
the process, we discuss tips and tricks for upgrading and show
how specific errors were fixed.
Porting to the Universal Windows Platform Contains information about porting code to Windows 10
Introduction to Visual C++ for UNIX Users Provides information for UNIX users who are new to Visual
C++ and want to become productive with it.
Porting from UNIX to Win32 Discusses options for migrating UNIX applications to
Windows.
See Also
Visual C++
Security Best Practices for C++
9/19/2018 • 3 minutes to read • Edit Online
This article contains information about security tools and practices. Using them does not make applications
immune from attack, but it makes successful attacks less likely.
Security-Enhanced CRT
The C Runtime Library (CRT) has been augmented to include secure versions of functions that pose security risks
—for example, the unchecked strcpy string copy function. Because the older, nonsecure versions of these
functions are deprecated, they cause compile-time warnings. We encourage you to use the secure versions of
these CRT functions instead of suppressing the compilation warnings. For more information, see Security Features
in the CRT.
SafeInt Library
SafeInt Library helps prevent integer overflows and other exploitable errors that might occur when the application
performs mathematical operations. The SafeInt library includes the SafeInt Class, the SafeIntException Class,
and several SafeInt Functions.
The SafeInt class protects against integer overflow and divide-by-zero exploits. You can use it to handle
comparisons between values of different types. It provides two error handling policies. The default policy is for the
SafeInt class to throw a SafeIntException class exception to report why a mathematical operation cannot be
completed. The second policy is for the SafeInt class to stop program execution. You can also define a custom
policy.
Each SafeInt function protects one mathematical operation from an exploitable error. You can use two different
kinds of parameters without converting them to the same type. To protect multiple mathematical operations, use
the SafeInt class.
Checked Iterators
A checked iterator enforces container boundaries. By default, when a checked iterator is out of bounds, it generates
an exception and ends program execution. A checked iterator provides other levels of response that depend on
values that are assigned to preprocessor defines such as _SECURE_SCL_THROWS and
_ITERATOR_DEBUG_LEVEL. For example, at _ITERATOR_DEBUG_LEVEL=2, a checked iterator provides
comprehensive correctness checks in debug mode, which are made available by using asserts. For more
information, see Checked Iterators and _ITERATOR_DEBUG_LEVEL.
See Also
System.Security
Security
How User Account Control (UAC ) Affects Your Application
Running as a Member of the Users Group
9/19/2018 • 2 minutes to read • Edit Online
This topic explains how configuring Windows user accounts as a member of the Users Group (as opposed to the
Administrators Group) increases security by reducing the chances of being infected with malicious code.
Security Risks
Running as an administrator makes your system vulnerable to several kinds of security attack, such as "Trojan
horse" and "buffer overrun." Merely visiting an Internet site as an administrator can be damaging to the system, as
malicious code that is downloaded from an Internet site may attack your computer. If successful, it inherits your
administrator permissions and can then perform actions such as deleting all your files, reformatting your hard
drive, and creating a new user accounts with administrative access.
Debugging
You can debug any applications that you launch within Visual Studio (native and unmanaged) as a non-
administrator by becoming part of the Debugging Group. This includes the ability to attach to a running
application using the Attach to Process command. However, it is necessary to be part of the Administrator Group
in order to debug native or managed applications that were launched by a different user.
See Also
Security Best Practices
How User Account Control (UAC) Affects Your
Application
9/19/2018 • 2 minutes to read • Edit Online
User Account Control (UAC ) is a feature of Windows Vista in which user accounts have limited privileges. You can
find detailed information about UAC at these sites:
Developer Best Practices and Guidelines for Applications in a Least Privileged Environment
This article contains guidance for developers to assist with identifying and mitigating speculative execution side
channel hardware vulnerabilities in C++ software. These vulnerabilities can disclose sensitive information across
trust boundaries and can affect software that runs on processors that support speculative, out-of-order execution
of instructions. This class of vulnerabilities was first described in January, 2018 and additional background and
guidance can be found in Microsoft's security advisory.
The guidance provided by this article is related to the classes of vulnerabilities represented by:
1. CVE -2017-5753, also known as Spectre variant 1. This hardware vulnerability class is related to side
channels that can arise due to speculative execution that occurs as a result of a conditional branch
misprediction. The Visual C++ compiler in Visual Studio 2017 (starting with version 15.5.5) includes
support for the /Qspectre switch which provides a compile-time mitigation for a limited set of potentially
vulnerable coding patterns related to CVE -2017-5753. The /Qspectre switch is also available in Visual
Studio 2015 Update 3 through KB 4338871. The documentation for the /Qspectre flag provides more
information on its effects and usage.
2. CVE -2018-3639, also known as Speculative Store Bypass (SSB ). This hardware vulnerability class is related
to side channels that can arise due to speculative execution of a load ahead of a dependent store as a result
of a memory access misprediction.
An accessible introduction to speculative execution side channel vulnerabilities can be found in the presentation
titled The Case of Spectre and Meltdown by one of the research teams that discovered these issues.
unsigned char ReadByte(unsigned char *buffer, unsigned int buffer_size, unsigned int untrusted_index) {
if (untrusted_index < buffer_size) {
unsigned char value = buffer[untrusted_index];
return shared_buffer[value * 4096];
}
}
In this example, ReadByte is supplied a buffer, a buffer size, and an index into that buffer. The index parameter, as
specified by untrusted_index , is supplied by a less privileged context, such as a non-administrative process. If
untrusted_index is less than buffer_size , then the character at that index is read from buffer and used to index
into a shared region of memory referred to by shared_buffer .
From an architectural perspective, this code sequence is perfectly safe as it is guaranteed that untrusted_index will
always be less than buffer_size . However, in the presence of speculative execution, it is possible that the CPU will
mispredict the conditional branch and execute the body of the if statement even when untrusted_index is greater
than or equal to buffer_size . As a consequence of this, the CPU may speculatively read a byte from beyond the
bounds of buffer (which could be a secret) and could then use that byte value to compute the address of a
subsequent load through shared_buffer .
While the CPU will eventually detect this misprediction, residual side effects may be left in the CPU cache that
reveal information about the byte value that was read out of bounds from buffer . These side effects can be
detected by a less privileged context running on the system by probing how quickly each cache line in
shared_buffer is accessed. The steps that can be taken to accomplish this are:
1. Invoke ReadByte multiple times with untrusted_index being less than buffer_size . The attacking
context can cause the victim context to invoke ReadByte (e.g. via RPC ) such that the branch predictor is
trained to be not-taken as untrusted_index is less than buffer_size .
2. Flush all cache lines in shared_buffer . The attacking context must flush all of the cache lines in the shared
region of memory referred to by shared_buffer . Since the memory region is shared, this is straightforward
and can be accomplished using intrinsics such as _mm_clflush .
3. Invoke ReadByte with untrusted_index being greater than buffer_size . The attacking context causes
the victim context to invoke ReadByte such that it incorrectly predicts that the branch will not be taken. This
causes the processor to speculatively execute the body of the if block with untrusted_index being greater
than buffer_size , thus leading to an out-of-bounds read of buffer . Consequently, shared_buffer is
indexed using a potentially secret value that was read out-of-bounds, thus causing the respective cache line
to be loaded by the CPU.
4. Read each cache line in shared_buffer to see which is accessed most quickly. The attacking context
can read each cache line in shared_buffer and detect the cache line that loads significantly faster than the
others. This is the cache line that is likely to have been brought in by step 3. Since there is a 1:1 relationship
between byte value and cache line in this example, this allows the attacker to infer the actual value of the
byte that was read out-of-bounds.
The above steps provide an example of using a technique known as FLUSH+RELOAD in conjunction with
exploiting an instance of CVE -2017-5753.
Kernel boundary A kernel-mode device driver that receives untrusted data from
a non-administrative user mode process may be at risk.
Applications that have attack surface exposed to any of the above trust boundaries should review code on the
attack surface to identify and mitigate possible instances of speculative execution side channel vulnerabilities. It
should be noted that trust boundaries exposed to remote attack surfaces, such as remote network protocols, have
not been demonstrated to be at risk to speculative execution side channel vulnerabilities.
unsigned char ReadByte(unsigned char *buffer, unsigned int buffer_size, unsigned int untrusted_index) {
if (untrusted_index < buffer_size) {
// SPECULATION BARRIER
unsigned char value = buffer[untrusted_index];
return shared_buffer[value * 4096];
}
}
Similarly, an array out-of-bounds load may occur in conjunction with a loop that exceeds its terminating condition
due to a misprediction. In this example, the conditional branch associated with the x < buffer_size expression
may mispredict and speculatively execute the body of the for loop when x is greater than or equal to
buffer_size , thus resulting in a speculative out-of-bounds load.
#define MAX_MESSAGE_ID 16
void DispatchMessage(unsigned int untrusted_message_id, unsigned char *buffer, unsigned int buffer_size) {
if (untrusted_message_id < MAX_MESSAGE_ID) {
// SPECULATION BARRIER
DispatchTable[untrusted_message_id](buffer, buffer_size);
}
}
As with the case of an array out-of-bounds load feeding another load, this condition may also arise in conjunction
with a loop that exceeds its terminating condition due to a misprediction.
Array out-of-bounds store feeding an indirect branch
While the previous example showed how a speculative out-of-bounds load can influence an indirect branch target,
it is also possible for an out-of-bounds store to modify an indirect branch target, such as a function pointer or a
return address. This can potentially lead to speculative execution from an attacker-specified address.
In this example, an untrusted index is passed through the untrusted_index parameter. If untrusted_index is less
than the element count of the pointers array (256 elements), then the provided pointer value in ptr is written to
the pointers array. This code is safe architecturally, but if the CPU mispredicts the conditional branch, it could
result in ptr being speculatively written beyond the bounds of the stack-allocated pointers array. This could lead
to speculative corruption of the return address for WriteSlot . If an attacker can control the value of ptr , they may
be able to cause speculative execution from an arbitrary address when WriteSlot returns along the speculative
path.
Similarly, if a function pointer local variable named func were allocated on the stack, then it may be possible to
speculatively modify the address that func refers to when the conditional branch misprediction occurs. This could
result in speculative execution from an arbitrary address when the function pointer is called through.
It should be noted that both of these examples involve speculative modification of stack-allocated indirect branch
pointers. It is possible that speculative modification could also occur for global variables, heap-allocated memory,
and even read-only memory on some CPUs. For stack-allocated memory, the Visual C++ compiler already takes
steps to make it more difficult to speculatively modify stack-allocated indirect branch targets, such as by reordering
local variables such that buffers are placed adjacent to a security cookie as part of the /GS compiler security
feature.
class CBaseType {
public:
CBaseType(TypeName type) : type(type) {}
TypeName type;
};
obj2->dispatch_routine();
return obj2->field2;
}
}
unsigned char ReadByte(unsigned char *buffer, unsigned int buffer_size, unsigned int trusted_index) {
unsigned int index;
// SPECULATION BARRIER
unsigned char value = buffer[index];
return shared_buffer[value * 4096];
}
void DispatchMessage(unsigned int untrusted_message_id, unsigned char *buffer, unsigned int buffer_size) {
MESSAGE_ROUTINE routine;
// SPECULATION BARRIER
routine(buffer, buffer_size);
}
Mitigation options
Speculative execution side channel vulnerabilities can be mitigated by making changes to source code. These
changes can involve mitigating specific instances of a vulnerability, such as by adding a speculation barrier, or by
making changes to the design of an application to make sensitive information inaccessible to speculative execution.
Speculation barrier via manual instrumentation
A speculation barrier can be manually inserted by a developer to prevent speculative execution from proceeding
along a non-architectural path. For example, a developer can insert a speculation barrier before a dangerous
coding pattern in the body of a conditional block, either at the beginning of the block (after the conditional branch)
or before the first load that is of concern. This will prevent a conditional branch misprediction from executing the
dangerous code on a non-architectural path by serializing execution. The speculation barrier sequence differs by
hardware architecture as described by the following table:
For example, the following code pattern can be mitigated by using the _mm_lfence intrinsic as shown below.
// A pointer to a shared memory region of size 1MB (256 * 4096)
unsigned char *shared_buffer;
unsigned char ReadByte(unsigned char *buffer, unsigned int buffer_size, unsigned int untrusted_index) {
if (untrusted_index < buffer_size) {
_mm_lfence();
unsigned char value = buffer[untrusted_index];
return shared_buffer[value * 4096];
}
}
It should be noted that the index masking performed here could be subject to speculative store bypass depending
on the code that is generated by the compiler.
unsigned char ReadByte(unsigned char *buffer, unsigned int buffer_size, unsigned int untrusted_index) {
if (untrusted_index < buffer_size) {
untrusted_index &= (buffer_size - 1);
unsigned char value = buffer[untrusted_index];
return shared_buffer[value * 4096];
}
}
See Also
Guidance to mitigate speculative execution side-channel vulnerabilities
Mitigating speculative execution side channel hardware vulnerabilities
Visual C++ Samples
8/22/2018 • 2 minutes to read • Edit Online
The Visual C++ samples listed below demonstrate different functionalities across multiple technologies.
Visual C++ samples
Visual Studio samples
Windows on GitHub
Universal Windows app samples
The All-In-One code framework
Windows Desktop code samples
MFC samples
CodePlex samples
ADO code samples
Windows Hardware development samples
IMPORTANT
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not
meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that
you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample
code "AS IS" with no warranties.
Visual C++ Help and Community
10/5/2018 • 2 minutes to read • Edit Online
Here's how to getting information about how to write C++ code and use the Visual Studio development tools.
Samples
TITLE DESCRIPTION
Developer Code Samples Contains downloadable sample code from Microsoft and
community contributors.
Product Documentation
TITLE DESCRIPTION
Windows Developer Center Contains information about how to use C++ and other
languages to develop apps for Windows 8. Part of the
Windows Developer Center; the C++ content is under the
Docs > Language Reference node.
Related Articles
TITLE DESCRIPTION
Visual C++ Team Blog Contains posts on various subjects by the experts on the
Visual C++ product team.
Channel 9 Contains video interviews and lectures. Use the search box on
the Channel 9 home page to find C++ content.
Visual Studio Contains articles and news about Visual Studio and related
development tools.
MSDN forums and Developer Community Official Microsoft forums where you can post questions about
C++ and get answers from Microsoft and from experts in the
community.
How to report a problem with the Visual C++ toolset
or documentation
10/2/2018 • 24 minutes to read • Edit Online
If you encounter problems with the Microsoft Visual C++ compiler, linker, or other tools and libraries, we want to
know about them. If the issue is in our documentation, we want to know about that, too.
Compiler Passes:
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe: Version 19.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\c1.dll: Version 19.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\c1xx.dll: Version 19.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\c2.dll: Version 19.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\link.exe: Version 14.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\mspdb140.dll: Version 14.14.26428.1
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\1033\clui.dll: Version 19.14.26428.1
Add any other details that might help us diagnose the problem you experienced, such as any work-arounds you
may have found. Avoid repeating information found elsewhere in your report.
The repro
A repro is a complete, self-contained source code example that reproducibly demonstrates the problem you've
encountered (hence the name). We need a repro so that we can reproduce the error on our machines. The code
should be sufficient by itself to create a simple executable that compiles and runs, or that would compile and run if
not for the problem you've found. A repro is not a code snippet; it should have complete functions and classes and
contain all the necessary #include directives, even for the standard headers.
What makes a good repro
A good repro is:
Minimal. Repros should be as small as possible yet still demonstrate exactly the problem you encountered.
Repros do not need to be complex or realistic; they only need to show code that conforms to the Standard
or the documented compiler implementation, or in the case of a missing diagnostic, the code that is not
conformant. Simple, to-the-point repros that contain just enough code to demonstrate the problem are best.
If you can eliminate or simplify the code and remain conformant and also leave the issue unchanged, please
do so. You do not need to include counter-examples of code that works.
Self-Contained. Repros should avoid unnecessary dependencies. If you can reproduce the problem
without third-party libraries, please do so. If you can reproduce the problem without any library code
besides simple output statements (for example, puts("this shouldn't compile"); , std::cout << value; , and
printf("%d\n", value); are okay), please do so. It's ideal if the example can be condensed to a single source
code file, without reference to any user headers. Reducing the amount of code we have to consider as a
possible contributor to the problem is enormously helpful to us.
Against the latest compiler version. Repros should use the most recent update to the latest version of
the toolset, or the most recent prerelease version of the next update or next major release, whenever
possible. Problems you may encounter in older versions of the toolset have very often been fixed in newer
versions. Fixes are backported to older versions only in exceptional circumstances.
Checked against other compilers if relevant. Repros that involve portable C++ code should verify
behavior against other compilers if possible. The Standard ultimately determines program correctness, and
no compiler is perfect, but when Clang and GCC accept your code without a diagnostic and MSVC does not,
it's likely you're looking at a bug in our compiler. (Other possibilities include differences in Unix and
Windows behavior, or different levels of C++ standards implementation, and so on.) On the other hand, if
all the compilers reject your code, then it's likely that your code is incorrect. Seeing different error messages
may help you diagnose the issue yourself.
You can find lists of online compilers to test your code against in Online C++ compilers on the ISO C++
website, or this curated List of Online C++ Compilers on GitHub. Some specific examples include Wandbox,
Compiler Explorer, and Coliru.
NOTE
The online compiler websites are not affiliated with Microsoft. Many online compiler websites are run as personal
projects, and some of these sites may not be available when you read this, but a search should find others you can
use.
Problems in the compiler, linker, and in the libraries, tend to show themselves in particular ways. The kind of
problem you encounter will determine what kind of repro you should include in your report. Without an
appropriate repro, we have nothing to investigate. Here are a few of the kinds of issues that you may see, and
instructions for generating the kinds of repros you should use to report each kind of problems.
Frontend (parser) crash
Frontend crashes occur during the parsing phase of the compiler. Typically, the compiler will emit Fatal Error
C1001 and reference the source code file and line number on which the error occurred; it will often mention a file
msc1.cpp, but you can ignore this detail.
For this kind of crash, please provide a Preprocessed Repro.
Here's example compiler output for this kind of crash:
SandBoxHost.cpp
d:\o\dev\search\foundation\common\tools\sandbox\managed\managed.h(929):
fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1369)
To work around this problem, try simplifying or changing the program near the
locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
d:\o\dev\search\foundation\common\tools\sandbox\managed\managed.h(929):
note: This diagnostic occurred in the compiler generated function
'void Microsoft::Ceres::Common::Tools::Sandbox::SandBoxedProcess::Dispose(bool)'
Internal Compiler Error in d:\o\dev\otools\bin\x64\cl.exe. You will be prompted
to send an error report to Microsoft later.
INTERNAL COMPILER ERROR in 'd:\o\dev\otools\bin\x64\cl.exe'
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
If the line that begins with INTERNAL COMPILER ERROR mentions link.exe, rather than cl.exe, LTCG was
enabled and you should provide a Link Repro. If its not clear whether LTCG was enabled from the compiler error
message, you may need to examine the command line arguments that you copied from your build log in a
previous step for the /GL command-line argument.
Linker crash
Linker crashes occur during the linking phase, after the compiler has run. Typically, the linker will emit Linker Tools
Error LNK1000.
NOTE
If the output mentions C1001 or involves Link-Time Code Generation, refer to Backend (code generation) crash instead for
more information.
Version 14.00.22816.0
ExceptionCode = C0000005
ExceptionFlags = 00000000
ExceptionAddress = 00007FF73C9ED0E6 (00007FF73C9E0000)
"z:\tools\bin\x64\link.exe"
NumberParameters = 00000002
ExceptionInformation[ 0] = 0000000000000000
ExceptionInformation[ 1] = FFFFFFFFFFFFFFFF
CONTEXT:
NOTE
Preprocessed repros are not as useful for problems that might be the result of bugs in our standard library implementation,
because we will often want to substitute our latest, in-progress implementation to see whether we've already fixed the
problem. In this case, don't preprocess the repro, and if you can't reduce the problem to a single source file, package your
code into a .zip file or similar, or consider using an IDE project repro. For more information, see Other repros.
NOTE
Regardless of how you submit your report, Microsoft respects your privacy. Microsoft is committed to compliance with all
data privacy laws and regulations. For information about how we treat the data that you send us, see the Microsoft Privacy
Statement.
TIP
For other kinds of problems you might encounter in Visual Studio that are not related to the C++ toolset (For example, UI
issues, broken IDE functionality, or general crashes), use the Report a Problem tool in the IDE. This is the best choice, due
to its screenshot capabilities and its ability to record UI actions that lead to the problem you've encountered. These kinds of
errors can also be looked up on the Developer Community site. For more information, see How to report a problem with
Visual Studio.