Skip to content

Commit c6d80d5

Browse files
authored
Merge pull request #5794 from Rageking8/add-example-in-c2154-error-reference
Add example in C2154 error reference
2 parents 3bff02d + 72be0ba commit c6d80d5

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
---
22
title: "Compiler Error C2154"
33
description: "Learn more about: Compiler Error C2154"
4-
ms.date: 11/04/2016
4+
ms.date: 09/21/2025
55
f1_keywords: ["C2154"]
66
helpviewer_keywords: ["C2154"]
77
---
88
# Compiler Error C2154
99

10-
> 'type' : only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'
10+
> '*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'
1111
1212
## Remarks
1313

14-
You can only get the underlying type of an enumeration type.
14+
You can only get the underlying type of an [enumeration](../../cpp/enumerations-cpp.md) type.
1515

16-
For more information, see [Compiler Support for Type Traits](../../extensions/compiler-support-for-type-traits-cpp-component-extensions.md).
16+
## Example
17+
18+
The following example generates C2154:
19+
20+
```cpp
21+
// C2154.cpp
22+
// compile with: /c
23+
24+
struct S {};
25+
enum E {};
26+
enum class EC {};
27+
28+
__underlying_type(S) s; // C2154
29+
__underlying_type(int) i; // C2154
30+
__underlying_type(E) e; // OK
31+
__underlying_type(EC) ec; // OK
32+
```
33+
34+
## See also
35+
36+
[`underlying_type` class](../../standard-library/underlying-type-class.md)

docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The articles in this section of the documentation explain a subset of the error
6969
|[Compiler error C2151](compiler-error-c2151.md)|more than one language attribute|
7070
|[Compiler error C2152](compiler-error-c2152.md)|'*identifier*': pointers to functions with different attributes|
7171
|[Compiler error C2153](compiler-error-c2153.md)|integer literals must have at least one digit|
72-
|[Compiler error C2154](compiler-error-c2154.md)|'*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '*trait*'|
72+
|[Compiler error C2154](compiler-error-c2154.md)|'*type*': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'|
7373
|[Compiler error C2155](compiler-error-c2155.md)|'?': invalid left operand, expected arithmetic or pointer type|
7474
|[Compiler error C2156](compiler-error-c2156.md)|pragma must be outside function|
7575
|[Compiler error C2157](compiler-error-c2157.md)|'*identifier*': must be declared before use in pragma list|

0 commit comments

Comments
 (0)