Skip to content

Repo sync for protected CLA branch #3198

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 12 commits into from
Jun 14, 2021
57 changes: 57 additions & 0 deletions docs/code-quality/c6389.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: C6389
description: "Describes the Microsoft C/C++ code analysis warning C6389, its causes, and how to address it."
ms.date: 06/09/2021
f1_keywords: ["C6389"]
helpviewer_keywords: ["C6389"]
---

# C6389: MARK_INTERNAL_OR_MISSING_COMMON_DECL

This check is intended to help reduce the visibility of certain symbols and to modularize the code. In multi-file C++ projects, each declaration should be either local to a C++ file (part of the anonymous namespace) or declared in a common header file that's included by multiple C++ files.

When this check flags a declaration, either it should be moved to an anonymous namespace or a forward declaration should be moved to a header file, depending on the scope of the symbol.

The rule is an experimental rule that must be explicitly enabled in a rule set file to work. For more information about rule sets, see [Use rule sets to group code analysis rules](/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules).

## Example

```cpp
// A.h
struct X;
```

```cpp
// A.cpp
#include "A.h"

// Not flagged, declared in a header file.
struct X { int x; };

struct Y { double y; }; // warning: Move 'Y' to anonymous namespace or put a forward declaration in a common header included in this file.

void f(); // warning: Move 'f' to anonymous namespace or put a forward declaration in a common header included in this file.
```

One way to resolve these issues is to move `struct Y` into an anonymous namespace, and move the declaration of `f` into a header:

```cpp
// A.h
struct X;
void f();
```

```cpp
// A.cpp
#include "A.h"

// Not flagged, declared in a header file.
struct X { int x; };

namespace {
struct Y { double y; };
} // anonymous namespace

// Not flagged, declared in a header file.
void f();
```
2 changes: 2 additions & 0 deletions docs/code-quality/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@
href: ../code-quality/c6387.md
- name: C6388
href: ../code-quality/c6388.md
- name: C6389
href: ../code-quality/c6389.md
- name: C6400
href: ../code-quality/c6400.md
- name: C6401
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The articles in this section of the documentation explain a subset of the error
|[Compiler error C2734](compiler-error-c2734.md)|'*identifier*': 'const' object must be initialized if not 'extern'|
|[Compiler error C2735](compiler-error-c2735.md)|'*keyword*' keyword is not permitted in formal parameter type specifier|
|[Compiler error C2736](compiler-error-c2736.md)|'*keyword*' keyword is not permitted in cast|
|Compiler error C2737|'*identifier*': 'constexpr' object must be initialized|
|Compiler error C2737|'*identifier*': `const`/`constexpr` object must be initialized|
|[Compiler error C2738](compiler-error-c2738.md)|'operator *type*': is ambiguous or is not a member of '*class*'|
|[Compiler error C2739](compiler-error-c2739.md)|'*number*': explicit managed/WinRT array dimensions must be between 1 and 32|
|Compiler error C2740|value of operand '*number*' is out of range '*lower_bound* - *upper_bound*'|
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: 06/07/2021
ms.date: 06/11/2021
helpviewer_keywords: ["warnings, by compiler version", "cl.exe compiler, setting warning options"]
---
# Compiler Warnings by compiler version
Expand Down Expand Up @@ -41,13 +41,23 @@ These versions of the compiler introduced new warnings:
| Visual Studio 2019 version 16.8 | 19.28.29330.0 |
| Visual Studio 2019 version 16.9 | 19.28.29500.0 |
| Visual Studio 2019 version 16.10 | 19.28.30000.0 |
| Visual Studio 2019 version 16.11 | 19.28.30100.0 |

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-160"

## Warnings introduced in Visual Studio 2019 version 16.11 (compiler version 19.29.30100.0)

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

| Warning | Message |
|--|--|
| C5247 | `section 'section-name' is reserved for C++ dynamic initialization. Manually creating the section will interfere with C++ dynamic initialization and may lead to undefined behavior` |
| C5248 | `section 'section-name' is reserved for C++ dynamic initialization. Variables manually put into the section may be optimized out and their order relative to compiler generated dynamic initializers is unspecified` |

## Warnings introduced in Visual Studio 2019 version 16.10 (compiler version 19.29.30000.0)

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