Skip to content
Closed
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
49 changes: 49 additions & 0 deletions docs/code-quality/c6389.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
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 intended to help with reducing the visibility of certain symbols and 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 is 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.

This is an experimental rule that needs to be enabled in a ruleset file explicitly to work. More information about rulesets can be found [here](https://docs.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules).

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

// A.cpp

// 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 'Y' to anonymous namespace or put a forward declaration in a common header included in this file.
```
To resolve this issue:
```cpp
// A.h
struct X;
void f();

// A.cpp

// 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