cpp-docs
cpp-docs copied to clipboard
Add example in C2154 error reference
- Add new example that generates C2154.
- In the error index page, change
*trait*to__underlying_typeas it seems to be the only trait that can cause C2154 (also to ensure both instances of the C2154 error message are identical). - Remove link to
Compiler Support for Type Traitsas there is no mention of__underlying_type. In fact, across the entire repository, the only mention of__underlying_typeis in this error topic. - Add links to
enumerationandunderlying_type.
Example
// 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
Visual Studio 2022
C:\Test>cl /c C2154.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35217 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
C2154.cpp
C2154.cpp(8): error C2154: 'S': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'
C2154.cpp(9): error C2154: 'int': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'
Visual Studio 2026 Insiders
C:\Test>cl /c C2154.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35503 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
C2154.cpp
C2154.cpp(8): error C2154: 'S': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'
C2154.cpp(9): error C2154: 'int': only enumeration type is allowed as an argument to compiler intrinsic type trait '__underlying_type'