From 09f465101094373a1eaa8f9295557ac480dba3f6 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 12 Aug 2025 00:40:21 +0800 Subject: [PATCH 1/5] Merge and condense `mutable` remarks in C2178 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2178.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md index ce0dfb543f..37211d190e 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md @@ -11,9 +11,7 @@ helpviewer_keywords: ["C2178"] ## Remarks -A **`mutable`** specifier was used in a declaration, but the specifier is not allowed in this context. - -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. +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). ## Example From db8eef149c6aa4e5397173c6e2d880a160b54442 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 12 Aug 2025 00:53:41 +0800 Subject: [PATCH 2/5] Improve `mutable` example in C2178 error reference --- .../compiler-errors-1/compiler-error-c2178.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md index 37211d190e..71d8840697 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md @@ -13,19 +13,18 @@ helpviewer_keywords: ["C2178"] 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). -## Example +## Example: `mutable` -The following example shows how C2178 may occur, and how to fix it. +The following example shows how C2178 may occur with the **`mutable`** specifier, and how to resolve it: ```cpp -// C2178.cpp -// compile with: cl /c /W4 C2178.cpp +// C2178_mutable.cpp +// compile with: /c -class S { - mutable const int i; // C2178 - // To fix, declare either const or mutable, not both. +struct S +{ + mutable const int i; // C2178, remove mutable or const to resolve }; -mutable int x = 4; // C2178 -// To fix, remove mutable keyword +mutable int x = 4; // C2178, remove mutable to resolve ``` From 69de9153bb8df413df1f65d828ddcbd9aa6c9700 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 12 Aug 2025 01:09:08 +0800 Subject: [PATCH 3/5] Add remarks on `consteval` in C2178 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2178.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md index 71d8840697..c3c17849f1 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md @@ -13,6 +13,8 @@ helpviewer_keywords: ["C2178"] 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). +A **`consteval`** specifier was used on a [destructor](../../cpp/destructors-cpp.md), allocation function, or deallocation function. + ## Example: `mutable` The following example shows how C2178 may occur with the **`mutable`** specifier, and how to resolve it: From c2143792f68dcee1ec82cc9d218a523e80818cbe Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 12 Aug 2025 01:15:28 +0800 Subject: [PATCH 4/5] Add `consteval` example in C2178 error reference --- .../compiler-errors-1/compiler-error-c2178.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md index c3c17849f1..4482c04017 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md @@ -30,3 +30,22 @@ struct S mutable int x = 4; // C2178, remove mutable to resolve ``` + +## Example: `consteval` + +The following example shows how C2178 may occur with the **`consteval`** specifier. To resolve this error, remove all **`consteval`** specifiers: + +```cpp +// C2178_consteval.cpp +// compile with: /c /std:c++20 + +#include + +struct S +{ + consteval ~S() {} // C2178 + + consteval static void* operator new(std::size_t size); // C2178 + consteval static void operator delete(void* ptr); // C2178 +}; +``` From 7f4c5e6438ed1ee764792713d171d8fc0851cbbe Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 12 Aug 2025 01:16:43 +0800 Subject: [PATCH 5/5] Update `ms.date` metadata in C2178 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2178.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md index 4482c04017..4c93e6c79d 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2178.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2178.md @@ -1,7 +1,7 @@ --- title: "Compiler Error C2178" description: "Learn more about: Compiler Error C2178" -ms.date: 05/08/2017 +ms.date: 08/11/2025 f1_keywords: ["C2178"] helpviewer_keywords: ["C2178"] ---