From 9a341508b0a5c6180280281be661fcfe38172ba0 Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Sun, 21 Sep 2025 21:20:55 +0800 Subject: [PATCH 1/5] Update C2154 error message --- docs/error-messages/compiler-errors-1/compiler-error-c2154.md | 2 +- .../compiler-errors-1/compiler-errors-c2100-through-c2199.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md index 021703b64ec..857a965dae8 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md @@ -7,7 +7,7 @@ helpviewer_keywords: ["C2154"] --- # Compiler Error C2154 -> 'type' : only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type' +> '*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type' ## Remarks diff --git a/docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md b/docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md index ef2e8e4b3f9..676b397bbbf 100644 --- a/docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md +++ b/docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md @@ -69,7 +69,7 @@ The articles in this section of the documentation explain a subset of the error |[Compiler error C2151](compiler-error-c2151.md)|more than one language attribute| |[Compiler error C2152](compiler-error-c2152.md)|'*identifier*': pointers to functions with different attributes| |[Compiler error C2153](compiler-error-c2153.md)|integer literals must have at least one digit| -|[Compiler error C2154](compiler-error-c2154.md)|'*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '*trait*'| +|[Compiler error C2154](compiler-error-c2154.md)|'*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'| |[Compiler error C2155](compiler-error-c2155.md)|'?': invalid left operand, expected arithmetic or pointer type| |[Compiler error C2156](compiler-error-c2156.md)|pragma must be outside function| |[Compiler error C2157](compiler-error-c2157.md)|'*identifier*': must be declared before use in pragma list| From adb67a2fb7ff743e3933477b3480cf7f1b77016d Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Sun, 21 Sep 2025 21:26:21 +0800 Subject: [PATCH 2/5] Update remarks in C2154 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2154.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md index 857a965dae8..095171b4ea2 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md @@ -11,6 +11,4 @@ helpviewer_keywords: ["C2154"] ## Remarks -You can only get the underlying type of an enumeration type. - -For more information, see [Compiler Support for Type Traits](../../extensions/compiler-support-for-type-traits-cpp-component-extensions.md). +You can only get the underlying type of an [enumeration](../../cpp/enumerations-cpp.md) type. From 99d7aee2fcd94b09b366123f12f91b747b108207 Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Sun, 21 Sep 2025 21:35:30 +0800 Subject: [PATCH 3/5] Add example in C2154 error reference --- .../compiler-errors-1/compiler-error-c2154.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md index 095171b4ea2..635b2dc2d6d 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md @@ -12,3 +12,21 @@ helpviewer_keywords: ["C2154"] ## Remarks You can only get the underlying type of an [enumeration](../../cpp/enumerations-cpp.md) type. + +## Example + +The following example generates C2154: + +```cpp +// C2154.cpp +// compile with: /c + +struct S {}; +enum E {}; +enum class EC {}; + +__underlying_type(S) s; // C2154 +__underlying_type(int) i; // C2154 +__underlying_type(E) e; // OK +__underlying_type(EC) ec; // OK +``` From fade1318e60a192bb7d25d812f097a6cd84789cd Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Sun, 21 Sep 2025 21:38:27 +0800 Subject: [PATCH 4/5] Add `std::underlying_type` "See also" link in C2154 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2154.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md index 635b2dc2d6d..2140d751a01 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md @@ -30,3 +30,7 @@ __underlying_type(int) i; // C2154 __underlying_type(E) e; // OK __underlying_type(EC) ec; // OK ``` + +## See also + +[`underlying_type` class](../../standard-library/underlying-type-class.md) From 72be0ba0133af9f56815ec74c83d0e35edeb89ea Mon Sep 17 00:00:00 2001 From: Rageking8 Date: Sun, 21 Sep 2025 21:39:26 +0800 Subject: [PATCH 5/5] Update `ms.date` metadata in C2154 error reference --- docs/error-messages/compiler-errors-1/compiler-error-c2154.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md index 2140d751a01..38192df4ca8 100644 --- a/docs/error-messages/compiler-errors-1/compiler-error-c2154.md +++ b/docs/error-messages/compiler-errors-1/compiler-error-c2154.md @@ -1,7 +1,7 @@ --- title: "Compiler Error C2154" description: "Learn more about: Compiler Error C2154" -ms.date: 11/04/2016 +ms.date: 09/21/2025 f1_keywords: ["C2154"] helpviewer_keywords: ["C2154"] ---