Skip to content

Commit bc69614

Browse files
authored
Document warning C5267
1 parent 02e1daf commit bc69614

6 files changed

Lines changed: 69 additions & 1 deletion

File tree

docs/cpp/explicitly-defaulted-and-deleted-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This is convenient for simple types, but complex types often define one or more
3636
> - If a copy constructor or destructor is explicitly declared, then automatic generation of the copy-assignment operator is deprecated.
3737
> - If a copy-assignment operator or destructor is explicitly declared, then automatic generation of the copy constructor is deprecated.
3838
>
39-
> In both cases, Visual Studio continues to automatically generate the necessary functions implicitly, and does not emit a warning.
39+
> In both cases, Visual Studio continues to automatically generate the necessary functions implicitly, and does not emit a warning by default. Since Visual Studio 2022 version 17.7, [C5267](../error-messages/compiler-warnings/c5267.md) can be enabled to emit a warning.
4040
4141
The consequences of these rules can also leak into object hierarchies. For example, if for any reason a base class fails to have a default constructor that's callable from a deriving class—that is, a **`public`** or **`protected`** constructor that takes no parameters—then a class that derives from it cannot automatically generate its own default constructor.
4242

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "Compiler warning C5267"
3+
description: Compiler warning C5267 description and solution.
4+
ms.date: 11/08/2023
5+
f1_keywords: ["C5267"]
6+
helpviewer_keywords: ["C5267"]
7+
---
8+
# Compiler warning C5267
9+
10+
> definition of implicit copy constructor/assignment operator for '*type*' is deprecated because it has a user-provided assignment operator/copy constructor
11+
12+
## Remarks
13+
14+
Since C++11, when only the copy constructor or copy assignment operator is explicitly defined, the implicit generation of the other is deprecated. However, to preserve backwards compatibility, the special functions are still implicitly generated.
15+
16+
## Example
17+
18+
The following sample code shows the warning being emitted when a deprecated implicitly generated special function is called, without it being explicitly defined:
19+
20+
```cpp
21+
// C5267.cpp
22+
// compile using: /W4 /w45267
23+
struct CopyCtorOnly
24+
{
25+
CopyCtorOnly() = default;
26+
CopyCtorOnly(const CopyCtorOnly&) {} // C5267
27+
};
28+
29+
struct CopyAssignOpOnly
30+
{
31+
CopyAssignOpOnly() = default;
32+
CopyAssignOpOnly& operator=(const CopyAssignOpOnly&) // C5267
33+
{
34+
return *this;
35+
}
36+
};
37+
38+
int main()
39+
{
40+
CopyCtorOnly a1, a2;
41+
a1 = a2; // Calls deprecated copy assignment operator
42+
43+
CopyAssignOpOnly b1;
44+
CopyAssignOpOnly b2 = b1; // Calls deprecated copy constructor
45+
}
46+
```
47+
48+
To resolve this issue explicitly define the missing copy constructor or copy assignment operator.
49+
50+
## See also
51+
52+
[Explicitly Defaulted and Deleted Functions](../../cpp/explicitly-defaulted-and-deleted-functions.md)

docs/error-messages/compiler-warnings/compiler-warnings-by-compiler-version.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ These versions of the compiler introduced new warnings:
4848
| Visual Studio 2022 version 17.3 | 19.33 |
4949
| Visual Studio 2022 version 17.4 | 19.34 |
5050
| Visual Studio 2022 version 17.5 | 19.35 |
51+
| Visual Studio 2022 version 17.7 | 19.37 |
5152

5253
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.
5354

5455
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.
5556

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

59+
## Warnings introduced in Visual Studio 2022 version 17.7 (compiler version 19.37)
60+
61+
These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.36`**.
62+
63+
| Warning | Message |
64+
|--|--|
65+
| C5267 | definition of implicit copy constructor/assignment operator for '*type*' is deprecated because it has a user-provided assignment operator/copy constructor |
66+
5867
## Warnings introduced in Visual Studio 2022 version 17.5 (compiler version 19.35)
5968

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

docs/error-messages/compiler-warnings/compiler-warnings-c4800-through-c4999.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ The articles in this section of the documentation explain a subset of the warnin
247247
| [Compiler warning (level 1, error, off) C5262](c5262.md) | implicit fall-through occurs here; are you missing a break statement? Use `[[fallthrough]]` when a `break` statement is intentionally omitted between cases |
248248
| Compiler warning (level 4, off) C5263 | calling '`std::move`' on a temporary object prevents copy elision |
249249
| Compiler warning (level 4, off) C5264 | '*variable-name*': 'const' variable is not used |
250+
| [Compiler warning C5267](c5267.md) | definition of implicit copy constructor/assignment operator for '*type*' is deprecated because it has a user-provided assignment operator/copy constructor |
250251
| Compiler warning (level 1, error) C5300 | '#pragma omp atomic': left operand of '*operator*' must match left hand side of assignment-expression |
251252
| [Compiler warning (level 1) C5301](c5301-c5302.md) | '#pragma omp for': '*loop-index*' increases while loop condition uses '*comparison*'; non-terminating loop? |
252253
| [Compiler warning (level 1) C5302](c5301-c5302.md) | '#pragma omp for': '*loop-index*' decreases while loop condition uses '*comparison*'; non-terminating loop? |

docs/error-messages/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,6 +4363,8 @@ items:
43634363
href: compiler-warnings/c5248.md
43644364
- name: Compiler warning (level 1, error, off) C5262
43654365
href: compiler-warnings/c5262.md
4366+
- name: Compiler warning C5267
4367+
href: compiler-warnings/c5267.md
43664368
- name: Compiler warning (level 1) C5301 and C5302
43674369
href: compiler-warnings/c5301-c5302.md
43684370
- name: Compiler warnings by compiler version

docs/preprocessor/compiler-warnings-that-are-off-by-default.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ The following warnings are turned off by default in Visual Studio 2022 and later
191191
| [C5262](../error-messages/compiler-warnings/c5262.md) (level 1, error) | implicit fall-through occurs here; are you missing a `break` statement? Use `[[fallthrough]]` when a `break` statement is intentionally omitted between cases <sup>17.4</sup> |
192192
| C5263 (level 4) | calling '`std::move`' on a temporary object prevents copy elision <sup>17.4</sup> |
193193
| C5264 (level 4) | '*variable-name*': 'const' variable is not used <sup>17.4</sup> |
194+
| [C5267](../error-messages/compiler-warnings/c5267.md) | definition of implicit copy constructor/assignment operator for '*type*' is deprecated because it has a user-provided assignment operator/copy constructor <sup>17.7</sup> |
194195

195196
<sup>14.1</sup> This warning is available starting in Visual Studio 2015 Update 1.\
196197
<sup>14.3</sup> This warning is available starting in Visual Studio 2015 Update 3.\
@@ -209,6 +210,9 @@ The following warnings are turned off by default in Visual Studio 2022 and later
209210
<sup>17.2</sup> This warning is available starting in Visual Studio 2022 version 17.2.\
210211
<sup>17.3</sup> This warning is available starting in Visual Studio 2022 version 17.3.\
211212
<sup>17.4</sup> This warning is available starting in Visual Studio 2022 version 17.4.\
213+
<sup>17.5</sup> This warning is available starting in Visual Studio 2022 version 17.5.\
214+
<sup>17.6</sup> This warning is available starting in Visual Studio 2022 version 17.6.\
215+
<sup>17.7</sup> This warning is available starting in Visual Studio 2022 version 17.7.\
212216
<sup>Perm</sup> This warning is off unless the [`/permissive-`](../build/reference/permissive-standards-conformance.md) compiler option is set.
213217

214218
## Warnings off by default in earlier versions

0 commit comments

Comments
 (0)