Skip to content

Commit d2c5bb4

Browse files
Merge pull request #4756 from Rageking8/update-c2534
Update C2534
2 parents 2d6ddca + da610dc commit d2c5bb4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@ ms.assetid: 481f9f54-5b51-4aa0-8eea-218f10807705
1010

1111
'identifier' : constructor cannot return a value
1212

13-
A constructor cannot return a value or have a return type (not even a **`void`** return type).
14-
15-
This error may be fixed by removing the **`return`** statement from the constructor definition.
13+
A constructor cannot contain a **`return`** statement with an expression (even if the expression has type **`void`**). This differs from regular void-returning function where a return expression of type **`void`** is allowed. However, using the **`return`** statement without an expression is allowed for early returns in the constructor.
1614

1715
The following sample generates C2534:
1816

1917
```cpp
2018
// C2534.cpp
19+
// compile with: /c
20+
void void_func() {}
21+
2122
class A {
2223
public:
2324
int i;
24-
A() { return i; } // C2534
25+
A() {
26+
return i; // C2534
27+
return 123; // C2534
28+
return (void)0; // C2534
29+
return void_func(); // C2534
30+
31+
return; // OK
32+
}
2533
};
2634
```
35+
36+
The preceding errors may be fixed by removing the entire **`return`** statement or omitting the return expression if an early return is desired.

0 commit comments

Comments
 (0)