Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2154.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
---
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"]
---
# 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

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

For more information, see [Compiler Support for Type Traits](../../extensions/compiler-support-for-type-traits-cpp-component-extensions.md).
## 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
```

## See also

[`underlying_type` class](../../standard-library/underlying-type-class.md)
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down