Which C++ versions are supported by specific Visual Studio versions? - c++

Which Visual Studio Version support C++11, C++14 or C++17?
I assume, that some version do support not all functions, but the question is aimed at the core functions.
Are there any differences between the Community Versions concerning the supported C++ version?
Thanks.

I find that this page should answer your question.
As for the Community Version, it supports the same C++ version as the other versions. The difference is in the tool provided(profiler, static analysis, etc.).

That’s a bit of a tricky question. For GCC/libstdc++ and Clang/libc++ the answer is usually pretty clear along the lines of: “Full support for all C++XX language and library features starting from version X.Y”.
But MSVC even in the very latest version does not have full support for C++11. On the other hand it already has a lot of the features from C++14 and even the upcoming C++17. So the question you’ll have to answer is: Which features do I want/need and from which version are they available? The links from the other question and its comments are a good starting point for this:
Support For C++11/14/17 Features (Modern C++)
Visual C++ Team Blog: C++17 Features In Visual Studio 2017 Version 15.3 Preview. There may be new versions of this blog post for newer VS versions as they are released. Look for posts by Stephan T. Lavavej to find the latest one. He is the maintainer of Microsoft’s standard library implementation.
As a rule of thumb I recommend you always go with the very latest version you can get your hands on. And if that’s not possible you probably don’t want to go older than VS 2015.
Microsoft constantly closes more and more of those older holes in their implementation. So probably and hopefully by C++20 or C++23 the situation will be similar to Clang or GCC.

Related

Is MSVC 2010 a C++11-standard-compliant compiler

I was about to use google test for unit testing our MSVC 2010 based project, but the README.md file of the gtest v1.10.x branch (the current latest) mentions a C++11-standard-compliant compiler in the Build Requirements section.
So is MSVC 2010 a C++11-standard-compliant compiler, or should I rather use gtest v1.7.0 which mentions Microsoft Visual C++ 7.1 or newer in the Windows Requirements section?
Around 2017, we had been facing too many random crashes with apps built using MSVC10 & MSVC11 compilers. Upon analyzing this, we identified that the standard C++ library calls were the cause for the crashes though we did nothing wrong, and the code was perfectly written.
After some struggle debugging and study, we identified that Microsoft's C++11 implementation was non standard and buggy, and caused unnecessary crashes. For us, even the basic wait_for call on condition_variable had random crashes. Here is one such MSDN reference for you.
We contacted Microsoft regarding this, and their reply was,
"I'm sorry, but no hotfixes for this bug are available. I strongly
recommend upgrading to the latest released version of VS (currently VS
2017 15.4), as we have fixed many bugs in the STL's multithreading
machinery over the years."
We had to move all our projects to VS2017 (The latest one at that time) to get rid of the crashes. I wouldn't recommend you using those buggy compilers either.
Better stick to older compilers(VC8/VC9) or move to the latest one (VS2019). We had no issues after migrating to VS2017.
No, MSVC 2010 is not fully C++11 compliant. However, it does provide many C++11 features. You could try and compile the latest google_test with it, or just use an older version.

Does Visual Studio 2019 v16.3.9 fully support C++20?

I`ve searched a lot and found different inforamation but unfortuantely could not understand Visual Studio 2019 fully supports C++20 or not!
According to my searches, there are 3 types of information:
Concepts and Modules are fully and partially supported, respectively. There is no support for Couroutines and Ranges. Also, Modules is still at the experimental stage.
There is no support except for Concepts.
All features are fully supported in MSVC and CLANG.
I`ve asked this question because I need to compile some sample code of new features introduced in C++20.
Note: The current and new version of VS2019 (at the time of asking this question) is 16.3.9.
Visual Studio 2019 v16.3.9 partially supports C++20.
By changing the MSVC compiler option from /std:c++17 to /std:c++latest, we can use the latest implemented features.
According to the question, type 1 or 2 of gathered information is more close to correct answer.
msvc partially supports concepts, as there say
Currently, MSVC doesn't support requires-expressions everywhere; they only work in concept definitions and in requires-clauses

How to compile with VS2017 for an older C++ standard?

I am using Visual Studio 2017 and need to create code that is compatible to VS2008 (C++03 or C++98). Is there a switch to restrict MSVC to C++03 features?
I am using CMake and tried to set
set_property(TARGET tgt PROPERTY CXX_STANDARD 98)
But this seems only to make sure, that the compiler supports C++98 or newer.
Any solution, that checks if C++ code uses features that are newer than the features supported by VS2008 will work as well. I just need to make sure, that I do not accidentally use features that are too new.
MSVC only got the standard switch in one of the updates to VS2015 (Update 3 to be exact) which was more or less C++14 compliant, and as such there are only switches for standards starting with C++14 (plus a few later features that were already implemented at the time of the update). All older features are enabled unconditionally for backwards compatibility (and because of all the work required to retrofit already implemented features for previous standards for virtually no gain).
See this blog post for more information: https://devblogs.microsoft.com/cppblog/standards-version-switches-in-the-compiler/
Also, note that there were a lot of conformance improvements in newer versions of MSVC, so even with the std switches you could write code that wouldn't work or would behave differently on older compiler.
A better solution would be just to use VS2008 toolset from VS2017 visual studio, as explained here: https://devblogs.microsoft.com/cppblog/stuck-on-an-older-toolset-version-move-to-visual-studio-2015-without-upgrading-your-toolset/
That way you'll be certain your code compiles on the older toolset, while using up-to-date IDE.

The C++ standard versions vs Visual Studio versions

The /std (Specify Language Standard Version) option is available in Visual Studio 2017 and later. Does it mean that previous versions of Visual Studio use particular versions of the C++ standard and, unlike gcc/clang, there's a 1:1 mapping between a VS version and the default C++ standard version provided by the compiler?
There is a blog post Standards version switches in the compiler that explains the introduction of the feature and what MSVC used to do previously:
Traditionally, we would release the compiler in a default mode that combines features striding several versions of the C++ language, e.g. C++98, C++03, C++11, C++14, etc. in addition to conformance improvement bug fixes. This can lead to situations where it is difficult to simultaneously upgrade to the newer and better compiler and at the same time move your code forward. We really appreciate the great feedback you’ve given us about our conformance improvements and new feature work. As the C++ standards committee is gearing up for a new C++ version, we’ve taken the initiative to help you state in your build systems or compiler command lines which version of C++ you are comfortable with while updating to the next version of Visual C++.
Visual C++ has made significant progress towards C++ standards conformance between the first release of Visual Studio 2015 and VS 2015 Update 3. We’ve fixed many issues with constexpr, improved expression SFINAE support, evaluation of initializer lists, variable templates, and more. Our standard library implementation has kept pace with features adopted into the post-C++14 standard draft. And we’ve implemented some major features currently under consideration by the committee, including C++ modules and coroutines. We want you to benefit from all this, but also we want you to consume these features at your own pace, while upgrading to this new update.
All post-C++14 features implemented in this update are off by default; those which were included in previous releases are left on to avoid causing your builds.
...
From what I gather /std:c++17 would be equivalent to clang/gcc -std=c++17 argument.
Some versions of msvc may not fully implement some versions of iso C++.
Depending on the Visual C++ compiler version or update level, certain C++14 or C++17 features may not be fully implemented or fully conformant when you specify the /std:c++14 or /std:c++17 options. For example, the Visual C++ 2017 RTM compiler does not fully support C++14-conformant constexpr, expression SFINAE, or 2-phase name lookup.
(cf: https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2017 )
So that's not exactly a "1:1 mapping between VS version and the default C++ standard version provided by the compiler".
You shouldn't rely on that.
Instead you should read the docs for the version of VS you're using.
Hope this answers your question.

What is the best compiler to use when you want to experiment with C++0x features?

What is the best compiler to experiment with C++0x features? I have been experimenting with GNU g++ 4.4.
Definitely GCC Trunk. ConceptGCC misses many features GCC trunk has. It is being merged into GCC currently though. It has all these features, including the new auto-typed variables (no new function declaration syntax yet though): http://gcc.gnu.org/projects/cxx0x.html .
There is a GCC branch containing partial lambda support, which also contains other C++0x features. I would recommend you to try that one out too. It's in use on #geordi at irc.freenode.org, you can experiment with it there.
Comeau - just for trying it online
ConceptGCC (wiki) was made for that purpose, if I am not mistaken.
It's probably not the best for C++0x experimentation, but for people who are MSVC oriented, there's a "Community Tech Preview" (CTP) of VS2010 which contains a preview of VC10 that has some parts of C++0x implemented (note that VC10 will not have the full set of C++0x changes implemented even when VC10 is released):
http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&displaylang=en
Some details on what's new in the VC10 CTP:
Visual Studio 2010 CTP released
Lambdas, auto, and static_assert: C++0x Features in VC10, Part 1
As noted in the above article, "The Visual C++ compiler in the Microsoft Visual Studio 2010 September Community Technology Preview (CTP) contains support for four C++0x language features, namely:"
lambdas,
auto,
static_assert,
rvalue references