Skip to content

Commit 6e7bba4

Browse files
authored
Merge pull request MicrosoftDocs#5069 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to main to sync with https://github.com/MicrosoftDocs/cpp-docs (branch main)
2 parents 206f054 + f5a1bc0 commit 6e7bba4

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

docs/error-messages/compiler-errors-1/compiler-error-c2397.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,22 @@ The C language allows implicit narrowing conversions in assignments and initiali
1515

1616
A narrowing conversion can be okay when you know the possible range of converted values can fit in the target. In this case, you know more than the compiler does. If you make a narrowing conversion intentionally, make your intentions explicit by using a static cast. Otherwise, this error message almost always indicates you have a bug in your code. You can fix it by making sure the objects you initialize have types that are large enough to handle the inputs.
1717

18-
The following sample generates C2397 and shows one way to fix it:
19-
20-
```
21-
// C2397.cpp -- C++ narrowing conversion diagnostics
22-
// Compile by using: cl /EHsc C2397.cpp
23-
#include <vector>
24-
25-
struct S1 {
26-
int m1;
27-
double m2, m3;
18+
The following sample generates C2397:
19+
20+
```cpp
21+
// C2397.cpp
22+
// compile with: /c
23+
struct S {
24+
int m1;
25+
double m2, m3;
2826
};
2927

30-
void function_C2397(double d1) {
31-
char c1 { 127 }; // OK
32-
char c2 { 513 }; // error C2397
33-
34-
std::vector<S1> vS1;
35-
vS1.push_back({ d1, 2, 3 }); // error C2397
36-
37-
// Possible fix if you know d1 always fits in an int
38-
vS1.push_back({ static_cast<int>(d1), 2, 3 });
28+
void func(double d1) {
29+
char c1 { 127 }; // OK
30+
char c2 { 513 }; // C2397
31+
32+
S arr[2]{};
33+
arr[0] = { d1, 2.0, 3.0 }; // C2397
34+
arr[1] = { static_cast<int>(d1), 2.0, 3.0 }; // OK
3935
}
4036
```

docs/error-messages/compiler-errors-2/compiler-error-c2510.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,18 @@ ms.assetid: bf6d28db-f2f4-48f8-8f4e-7d662ed278fe
1111
'identifier' : left of '::' must be a class/struct/union
1212

1313
A class, structure, or union name must appear on the left side of the scope-resolution operator (`::`) operator.
14+
15+
The following sample generates C2510:
16+
17+
```cpp
18+
// C2510.cpp
19+
struct S {
20+
static const int x = 1;
21+
};
22+
23+
int main() {
24+
S s;
25+
int num1 = s::x; // C2510
26+
int num2 = S::x; // OK
27+
}
28+
```
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
---
22
description: "Learn more about: Compiler Error C3551"
33
title: "Compiler Error C3551"
4-
ms.date: "11/04/2016"
4+
ms.date: "10/07/2023"
55
f1_keywords: ["C3551"]
66
helpviewer_keywords: ["C3551"]
77
ms.assetid: c8ee23da-6568-40db-93a6-3ddb7ac47712
88
---
99
# Compiler Error C3551
1010

11-
"expected a late specified return type"
11+
if a trailing return type is used then the leading return type shall be the single type-specifier 'auto' (not 'type')
1212

13-
If you use the **`auto`** keyword as a placeholder for the return type of a function, you must provide a late-specified return type. In the following example, the late-specified return type of function `myFunction` is a pointer to an array of four elements of type **`int`**.
13+
The leading return type in [trailing return type](../../cpp/functions-cpp.md#trailing-return-types) syntax must contain only `auto`.
1414

15-
```
16-
auto myFunction()->int(*)[4];
17-
```
15+
```cpp
16+
// C3551.cpp
17+
// compile with: /c
18+
const auto func1() -> const int; // C3551
19+
auto* func2() -> int*; // C3551
20+
auto& func3() -> int&; // C3551
21+
auto&& func4() -> int&&; // C3551
22+
decltype(auto) func5() -> int; // C3551
1823

19-
## See also
20-
21-
[auto](../../cpp/auto-cpp.md)
24+
auto func6() -> int; // OK
25+
```

0 commit comments

Comments
 (0)