Skip to content

Repo sync for protected CLA branch #4085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/code-quality/c26810.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ void bad_lambda_example1()
}
```

To fix this warning, consider using by-value arguments instead of captures:

```cpp
void bad_lambda_example1()
{
int x = 5;
auto good = [](int x) -> std::future<void> {
co_await ManualControl{g_suspended_coro};
printf("%d\n", x);
};
good(x);
}
```

Alternatively, if the coroutine is guaranteed to live shorter than the lambda object, use `gsl::suppress` to suppress the warning and document the lifetime contracts in a comment.

## See also

- [C26811](../code-quality/c26811.md)
13 changes: 13 additions & 0 deletions docs/code-quality/c26811.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ std::future<void> async_coro(int &a)
}
```


To fix this warning, consider taking the argument by value:

```cpp
std::future<void> async_coro(int a)
{
co_await ManualControl{g_suspended_coro};
++a;
}
```

Alternatively, when the lifetime of `a` is guaranteed to outlive the lifetime of the coroutine, suppress the warning using `gsl::suppress` and document the lifetime contracts of the code.

## See also

- [C26810](../code-quality/c26810.md)
17 changes: 9 additions & 8 deletions docs/cpp/tutorial-named-modules-cpp.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Named modules tutorial in C++"
ms.date: 02/10/2022
ms.date: 08/08/2022
ms.topic: "tutorial"
helpviewer_keywords: ["modules [C++]", "modules [C++], named modules tutorial"]
description: Named modules in C++20 provide a modern alternative to header files.
Expand Down Expand Up @@ -50,9 +50,9 @@ As we build a simple project, we'll look at various aspects of modules as we imp

To begin, in Visual Studio 2022, choose **Create a new project** and then the **Console App** (for C++) project type. If this project type isn't available, you may not have selected the **Desktop development with C++** workload when you installed Visual Studio. You can use the Visual Studio Installer to add the C++ workload.

Give the new project the name `ModulesTutorial` and create the project.
Give the new project the name *`ModulesTutorial`* and create the project.

Because modules are a C++20 feature, the project needs the [`/std:c++20` or `/std:c++latest`](../build/reference/std-specify-language-standard-version.md) compiler option. Set the **C++ Language Standard** property by right-clicking in the **Solution Explorer** on the project name `ModulesTutorial`, then choose `Properties`. In the project properties page that appears, ensure that `General` is selected on the left, and then change the **C++ Language Standard** dropdown to **ISO C++20 Standard (/std:c++20)**. Select **OK** to accept the change.
Because modules are a C++20 feature, the project needs the [`/std:c++20` or `/std:c++latest`](../build/reference/std-specify-language-standard-version.md) compiler option. To set the **C++ Language Standard** property, in **Solution Explorer**, right-click on the project name `ModulesTutorial`, then choose **Properties**. In the project Property Pages dialog, change **Configuration** to **All Configurations** and **Platform** to **All Platforms**. Select **Configuration Properties** > **General** in the tree view pane on the left. Select the **C++ Language Standard** property. Use the dropdown to change the property value to **ISO C++20 Standard (/std:c++20)**. Select **OK** to accept the change.

![A screenshot of the ModulesTutorial property page with the left pane open to Configuration Properties > General, and the C++ Language Standard dropdown open with ISO C++20 Standard (/std:c++20) selected](media/language-switch.png)

Expand All @@ -70,10 +70,11 @@ The default contents of the created module file has two lines:

```cpp
export module BasicPlane;

export void MyFunc();
```

The first line declares this file to be a module interface unit. Specifically, the `export module` keywords identify this file as a module interface unit. There's a subtle point here. For every named module, there must be exactly one module interface unit with no module partition specified. That module unit is called the primary module interface unit.
The first line declares this file to be a module interface unit. Specifically, the `export module` keywords identify this file as a module interface unit. There's a subtle point here: For every named module, there must be exactly one module interface unit with no module partition specified. That module unit is called the *primary module interface unit*.

The primary module interface unit is where you declare the functions, types, templates, other modules, and module partitions to expose when source files import the module. A module can consist of multiple files, but only the primary module interface file identifies what to expose.

Expand Down Expand Up @@ -101,7 +102,7 @@ When you import a partition into the primary module, all its declarations become

### `Point` module partition

To create a module partition file, in the **Solution Explorer**, right-click **Source Files**, then select **Add** > **Module**. Name the file *`BasicPlane.Figures-Point.ixx`* and select **Add**.
To create a module partition file, in the **Solution Explorer**, right-click **Source Files**, then select **Add** > **Module**. Name the file *`BasicPlane.Figures-Point.ixx`* and choose **Add**.

Because it's a module partition file, we've added a hyphen and the name of the partition to the module name. This convention aids the compiler in the command-line case: The compiler uses name lookup rules based on the module name to find the compiled *`.ifc`* file for the partition. This way you don't have to provide explicit `/reference` command-line arguments to find the partitions that belong to the module. It's also helpful for organizing the files that belong to a module by name. You can easily see which files belong to which modules.

Expand Down Expand Up @@ -182,7 +183,7 @@ So far, we've defined the primary module interface, which exposes the API surfac

## Create a module unit implementation file

Module unit implementation files don't end with an *`.ixx`* extension. They're normal *`.cpp`* files. Add a module unit implementation file by creating a source file with a right-click in the **Solution Explorer** on **Source Files**, select **Add** > **New item** and then select **C++ File (.cpp)**. Give the new file the name `BasicPlane.Figures-Rectangle.cpp`, then select **Add**.
Module unit implementation files don't end with an *`.ixx`* extension. They're normal *`.cpp`* files. Add a module unit implementation file by creating a source file with a right-click in the **Solution Explorer** on **Source Files**, select **Add** > **New item** and then select **C++ File (.cpp)**. Give the new file the name `BasicPlane.Figures-Rectangle.cpp`, then choose **Add**.

The naming convention for the module partition's implementation file follows the naming convention for partition. But it has a *`.cpp`* extension because it's an implementation file.

Expand All @@ -206,7 +207,7 @@ When you include a header file, you generally don't want it to be treated as an

The module implementation file we're building doesn't include any libraries because it doesn't need them as part of its implementation. But if it did, this area is where the `#include` directives would go.

The line `module BasicPlane.Figures;` identifies this file as part of the named module `BasicPlane.Figures`. The compiler automatically brings the types and functions exposed by the primary module interface into this file. A module implementation unit doesn't have the `export` keyword before the `module` keyword in its module-declaration.
The line `module BasicPlane.Figures:Rectangle;` identifies this file as part of the named module `BasicPlane.Figures`. The compiler automatically brings the types and functions exposed by the primary module interface into this file. A module implementation unit doesn't have the `export` keyword before the `module` keyword in its module-declaration.

Next are the definition of the functions `area()`, `height()`, and `width()`. They were declared in the `Rectangle` partition in `BasicPlane.Figures-Rectangle.ixx`. Because the primary module interface for this module imported the `Point` and `Rectangle` module partitions, those types are visible here in the module unit implementation file. An interesting feature of module implementation units: The compiler automatically makes everything in the corresponding module primary interface visible to the file. No `imports <module-name>` is needed.

Expand All @@ -232,7 +233,7 @@ int main()
}
```

The first line, `import BasicPlane.Figures;` makes all the exported functions and types from the `BasicPlane.Figures` module visible to this file. It can come before or after `#include` directives.
The line `import BasicPlane.Figures;` makes all the exported functions and types from the `BasicPlane.Figures` module visible to this file. It can come before or after `#include` directives.

The app then uses the types and functions from the module to output the area and width of the defined rectangle:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Compiler Warnings by compiler version"
description: "Table of Microsoft C/C++ compiler warnings by compiler version."
ms.date: 12/01/2021
ms.date: 08/08/2022
helpviewer_keywords: ["warnings, by compiler version", "cl.exe compiler, setting warning options"]
---
# Compiler Warnings by compiler version
Expand Down Expand Up @@ -44,13 +44,39 @@ These versions of the compiler introduced new warnings:
| Visual Studio 2019 version 16.11 | 19.29.30100.0 |
| Visual Studio 2022 version 17.0 RTW | 19.30 |
| Visual Studio 2022 version 17.1 | 19.31 |
| Visual Studio 2022 version 17.2 | 19.32 |
| Visual Studio 2022 version 17.3 | 19.33 |

You can specify only the major number, the major and minor numbers, or the major, minor, and build numbers to the **`/Wv`** option. The compiler reports all warnings that match versions that begin with the specified number. It suppresses all warnings for versions greater than the specified number. For example, **`/Wv:17`** reports warnings introduced in or before any version of Visual Studio 2012, and suppresses warnings introduced by any compiler from Visual Studio 2013 (version 18) or later. To suppress warnings introduced in Visual Studio 2015 update 2 and later, you can use **`/Wv:19.00.23506`**. Use **`/Wv:19.11`** to report the warnings introduced in any version of Visual Studio before Visual Studio 2017 version 15.5, but suppress warnings introduced in Visual Studio 2017 version 15.5 and later.

The following sections list the warnings introduced by each version of Visual C++ that you can suppress by using the **`/Wv`** compiler option. The **`/Wv`** option can't suppress warnings that aren't listed, which predate the specified versions of the compiler.

::: moniker range=">= msvc-170"

## Warnings introduced in Visual Studio 2022 version 17.3 (compiler version 19.33)

These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.32`**.

| Warning | Message |
|--|--|
| C5259 | '*specialized-type*': explicit specialization requires 'template <>' |

## Warnings introduced in Visual Studio 2022 version 17.2 (compiler version 19.32)

These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.31`**.

| Warning | Message |
|--|--|
| C4983 | '/analyze:sarif:hashname' ignored because the argument to '/analyze:log' is a single file rather than a directory |
| C5081 | Secure hotpatch is not supported with /GENPROFILE, /FASTGENPROFILE or /LTCG:PGI, disabling secure hotpatch. |
| C5255 | unterminated bidirectional character encountered: 'U+XXXX' |
| C5256 | '*enumeration*': a non-defining declaration of an enumeration with a fixed underlying type is only permitted as a standalone declaration |
| C5257 | '*enumeration*': enumeration was previously declared without a fixed underlying type |
| C5258 | explicit capture of '*symbol*' is not required for this use |
| C5300 | '#pragma omp atomic': left operand of '*operator*' must match left hand side of assignment-expression |
| C5301 | '#pragma omp for': '*symbol*' increases while loop condition uses '*comparison*'; non-terminating loop? |
| C5302 | '#pragma omp for': '*symbol*' decreases while loop condition uses '*comparison*'; non-terminating loop? |

## Warnings introduced in Visual Studio 2022 version 17.1 (compiler version 19.31)

These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.30`**.
Expand Down
Loading