C++20 Features in Visual Studio 2019 versions 16.7 and 16.8

Daniel Griffing

What’s New

We have continued our efforts to implement C++20 in the MSVC toolset, with noteworthy progress being made in VS (Visual Studio) 2019 v16.7 and VS 2019 v16.8. This blog post lists the features implemented since the C++20 Features and Fixes in VS 2019 16.1 through 16.6 blog post.

This blog post will specifically focus on language features implemented in the MSVC compiler (cl.exe). The changelog for conformance progress for the STL is tracked in the Standard Library changelog in the Microsoft STL GitHub repo.

Some of the features covered were already highlighted in the announcements made at CppCon 2020 in September related to the VS 2019 v16.8 Preview 3 release.

As a reminder, the /std:c++17 and /std:c++latest compiler options are necessary to use C++17 and C++20 features, respectively. 

 

VS 2019 v16.7

C++20 Language Feature Support

  • Implemented P1009R2 Array size deduction in new-expressions  
  • Implemented P0722R3 Efficient sized delete for variable sized classes 
  • Implemented P1094R2 Nested inline namespaces 
  • Implemented P1331R2 Permitting trivial default initialization in constexpr contexts 
  • Implemented P1816R0 CTAD for aggregates 
  • Implemented P0388R4 Permit conversions to arrays of unknown bound 
  • Implemented P1452R2 On the non-uniform semantics of return-type-requirements 
  • Implemented P1152R4 Deprecating volatile 
  • Implemented P1814R0 CTAD for alias templates 
  • Implemented P1972R0 US105 Check satisfaction of constraints for non-templates… 
  • Implemented P1980R0 CA096: Declaration matching for non-dependent requires-clauses 
  • Implemented P0528R3 Atomic compare-and-exchange with padding bits 
  • Implemented P1358R0 Type completeness and derived-to-base pointer conversions 
  • Implemented P0466R5 Layout-Compatibility and Pointer-Interconvertibility Traits 
  • Implemented P2107R0 US064 Copy semantics of coroutine parameters 
  • Implemented P2107R0 US052 Non-executed return statements in coroutines 
  • Implemented P2103R0 Allow “import” inside linkage-specifications [dcl.link] 
  • Implemented P2085R0 Consistent defaulted comparisons 
  • Implemented CWG 2280 Matching a usual deallocation function with placement new 
  • Implemented CWG 2382 Array allocation overhead for non-allocating placement new 
  • Implemented CWG 2441 Inline function parameters 
  • Implemented CWG 2282 Consistency with mismatched aligned/non-over-aligned allocation/deallocation functions 
  • Implemented US212 Converting from T* to bool should be considered narrowing 

 

VS 2019 v16.8

C++20 Language Feature Support

  • Implemented P1103R3 Modules 
  • Implemented P0912R5 Coroutines 
  • Implemented P1286R2 Contra CWG DR1778 
  • Implemented P0315R4 Allowing lambdas in unevaluated contexts 
  • Implemented P0960R3 Allow initializing aggregates from a parenthesized list of values 
  • Implemented P0848R3 Conditionally trivial special member functions 
  • Implemented P1811R0 Relaxing redefinition restrictions for re-exportation robustness 
  • Implemented P1766R1 Mitigating minor modules maladies 
  • Implemented P1975R0 Fixing the wording of parenthesized aggregate-initialization 
  • Implemented P1874R1 Dynamic Initialization Order of Non-Local Variables in Modules 

 

Two of the major features of C++20, Modules and Coroutines, are now feature-complete in the MSVC toolset and are now implied by the /std:c++latest compiler switch.  

Strict conformance mode (/permissive-) and /std:c++latest

As a prerequisite for Modules support, `/permissive-` is now enabled when /std:c++latest is specifiedSee /permissive- documentation regarding compiling code under `/permissive-`. 

For code that previously compiled under /std:c++latest and requires non-conformant compiler behaviors, `/permissive` may be specified to turn off strict conformance mode in the compiler and must appear after /std:c++latest in the command line argument list.  

However, specifying `/permissive` will result in an error if Modules usage is encountered: 

error C1214: Modules conflict with non-standard behavior requested via ‘[option]’

Where the most common values for [option] are: 

  • `/Zc:twoPhase` : Two Phase name lookup (`/Zc:twoPhase`) is required for C++20 Modules and implied by `/permissive-`See also [/Zc:twoPhase documentation](https://docs.microsoft.com/en-us/cpp/build/reference/zc-twophase?view=vs-2019).  
  • `/Zc:hiddenFriend` : Standard hidden friend name lookup rules are required for C++20 Modules and implied by `/permissive-`.  
  • `/Zc:preprocessor` : Use of the conformant preprocessor (/Zc:preprocessor) is required for C++20 header unit usage and creation onlyNamed Modules do not require this option. See also /Zc:preprocessor documentation](https://docs.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=vs-2019 

More Information

For Visual Studio changes (beyond the C++ toolset) and download links, see the VS Release Notes and VS Preview Release Notes. You can report bugs through Developer Community, and you can also report STL bugs via microsoft/STL GitHub issues.

 

 

Posted in C++

13 comments

Discussion is closed. Login to edit/delete existing comments.

  • James Wil 0

    Modules doesn’t work, i tried both the latest version of VS and the Preview

    error C3674: could not find standard library module 'std'

    and import std; shows in red

    export module Module;
    
    import std;
    
    export int main() {
        return 0;
    }

    I have enabled modules and latest c++ version on the project settings

    What else should i do?

    • Stanislav Ershov 0

      From the previous blog post

      The std.* Modules which ship with Visual Studio will not be available through /std:c++latest alone. The standard library Modules have not yet been standardized and as such remain experimental. To continue using the standard library Modules users will need /experimental:module as part of their command line options.

      • Daniel GriffingMicrosoft employee 0

        Thank you for the reply Stanislav!

        That is correct. ISO C++ has not yet standardized how the standard library will be organized with Modules. This is something that is being worked on for a future standard revision (hopefully C++23).

  • Alex Syniakov 0

    Tried to modularize my pet project – got a lot of “compiler internal error”(s). All errors occur around “global module fragment”

  • 屿 罗 0

    import STL headers doesn’t work with /experimental:module and /std:c++latest

    export module Print;
    import string; 
    import stdio.h; 
    namespace Print
    {
    	export void PrintLine(std::string msg)
    	{
    		printf("%s\n", msg.c_str());
    	}
    }
    
  • Noel Grandin 0

    The LibreOffice team would like to vote for std::source_location 🙂

    https://en.cppreference.com/w/cpp/utility/source_location

    We’re using it to add source information to exception throwing, which makes debugging much more pleasant

    • Daniel GriffingMicrosoft employee 0

      Thank you Noel!

      Support for std::source_location is on the short list of remaining C++20 features and I know that work is being done targeting a future VS release. You can follow progress of C++20 STL features here: https://github.com/microsoft/STL/projects/3.

      From the language/compiler perspective, I know that work is currently in progress that will enable the completion of this feature.

      Regards,
      –Daniel

  • Ravi kumar 0

    Hey friends, i wan’t to start developing desktop applications using visual studio, what do i need to learn for that, what steps to follow and what libraries to learn. Can u help me how to start using visual studio for that.

Feedback usabilla icon