Skip to content

Commit b0561d9

Browse files
Merge pull request #5650 from Rageking8/augment-c2178-error-reference-with-consteval
Augment C2178 error reference with `consteval`
2 parents e514375 + 7f4c5e6 commit b0561d9

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Error C2178"
33
description: "Learn more about: Compiler Error C2178"
4-
ms.date: 05/08/2017
4+
ms.date: 08/11/2025
55
f1_keywords: ["C2178"]
66
helpviewer_keywords: ["C2178"]
77
---
@@ -11,23 +11,41 @@ helpviewer_keywords: ["C2178"]
1111
1212
## Remarks
1313

14-
A **`mutable`** specifier was used in a declaration, but the specifier is not allowed in this context.
14+
A **`mutable`** specifier was used in a declaration, but the specifier is not allowed in this context. It can only be applied to non-static, non-const, and non-reference data members. For more information, see [Mutable Data Members](../../cpp/mutable-data-members-cpp.md).
1515

16-
The **`mutable`** specifier can be applied only to names of class data members, and cannot be applied to names declared **`const`** or **`static`**, and cannot be applied to reference members.
16+
A **`consteval`** specifier was used on a [destructor](../../cpp/destructors-cpp.md), allocation function, or deallocation function.
1717

18-
## Example
18+
## Example: `mutable`
1919

20-
The following example shows how C2178 may occur, and how to fix it.
20+
The following example shows how C2178 may occur with the **`mutable`** specifier, and how to resolve it:
2121

2222
```cpp
23-
// C2178.cpp
24-
// compile with: cl /c /W4 C2178.cpp
23+
// C2178_mutable.cpp
24+
// compile with: /c
2525

26-
class S {
27-
mutable const int i; // C2178
28-
// To fix, declare either const or mutable, not both.
26+
struct S
27+
{
28+
mutable const int i; // C2178, remove mutable or const to resolve
2929
};
3030

31-
mutable int x = 4; // C2178
32-
// To fix, remove mutable keyword
31+
mutable int x = 4; // C2178, remove mutable to resolve
32+
```
33+
34+
## Example: `consteval`
35+
36+
The following example shows how C2178 may occur with the **`consteval`** specifier. To resolve this error, remove all **`consteval`** specifiers:
37+
38+
```cpp
39+
// C2178_consteval.cpp
40+
// compile with: /c /std:c++20
41+
42+
#include <cstddef>
43+
44+
struct S
45+
{
46+
consteval ~S() {} // C2178
47+
48+
consteval static void* operator new(std::size_t size); // C2178
49+
consteval static void operator delete(void* ptr); // C2178
50+
};
3351
```

0 commit comments

Comments
 (0)