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
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
---
description: "Learn more about: Compiler Warning (level 1) C4541"
title: "Compiler Warning (level 1) C4541"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4541"
ms.date: 08/24/2025
f1_keywords: ["C4541"]
helpviewer_keywords: ["C4541"]
ms.assetid: b57b8f3e-117d-4fc2-bba6-faec17e5fa9d
---
# Compiler Warning (level 1) C4541

'identifier' used on polymorphic type 'type' with /GR-; unpredictable behavior may result
> '*operator*' used on polymorphic type '*type*' with /GR-; unpredictable behavior may result

## Remarks

You tried to use the [`dynamic_cast` operator](../../cpp/dynamic-cast-operator.md) or [`typeid` operator](../../cpp/typeid-operator.md), which requires [Run-Time Type Information](../../cpp/run-time-type-information.md) (RTTI), without enabling it. To enable RTTI, recompile with [`/GR`](../../build/reference/gr-enable-run-time-type-information.md).

## Example

The following example generates C4541:

```cpp
// C4541.cpp
// compile with: /W1 /GR-

#include <typeinfo>

struct Base
{
virtual ~Base() {}
};

struct Derived : Base {};

int main()
{
Derived derived;
Base* pointer_to_base = &derived;

dynamic_cast<Derived*>(pointer_to_base); // C4541

You tried to use a feature that requires run-time type information without enabling run-time type information. Recompile with [/GR](../../build/reference/gr-enable-run-time-type-information.md).
typeid(*pointer_to_base); // C4541
typeid(pointer_to_base); // OK
}
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Microsoft C/C++ compiler (MSVC) warnings C4400 through C4599"
description: "Table of Microsoft C/C++ compiler (MSVC) warnings C4400 through C4599"
ms.date: "1/22/2025"
ms.date: 1/22/2025
f1_keywords: ["C4413", "C4415", "C4416", "C4417", "C4418", "C4419", "C4421", "C4423", "C4424", "C4425", "C4426", "C4427", "C4438", "C4442", "C4443", "C4444", "C4446", "C4447", "C4448", "C4449", "C4450", "C4451", "C4452", "C4453", "C4454", "C4455", "C4466", "C4467", "C4468", "C4472", "C4474", "C4475", "C4476", "C4478", "C4480", "C4482", "C4483", "C4491", "C4492", "C4493", "C4494", "C4495", "C4496", "C4497", "C4498", "C4499", "C4509", "C4519", "C4531", "C4542", "C4562", "C4568", "C4569", "C4573", "C4574", "C4575", "C4576", "C4578", "C4582", "C4583", "C4585", "C4586", "C4587", "C4588", "C4589", "C4591", "C4592", "C4593", "C4594", "C4595", "C4598", "C4599"]
helpviewer_keywords: ["C4413", "C4415", "C4416", "C4417", "C4418", "C4419", "C4421", "C4423", "C4424", "C4425", "C4426", "C4427", "C4438", "C4442", "C4443", "C4444", "C4446", "C4447", "C4448", "C4449", "C4450", "C4451", "C4452", "C4453", "C4454", "C4455", "C4466", "C4467", "C4468", "C4472", "C4474", "C4475", "C4476", "C4478", "C4480", "C4482", "C4483", "C4491", "C4492", "C4493", "C4494", "C4495", "C4496", "C4497", "C4498", "C4499", "C4509", "C4519", "C4531", "C4542", "C4562", "C4568", "C4569", "C4573", "C4574", "C4575", "C4576", "C4578", "C4582", "C4583", "C4585", "C4586", "C4587", "C4588", "C4589", "C4591", "C4592", "C4593", "C4594", "C4595", "C4598", "C4599"]
---
Expand Down Expand Up @@ -139,7 +139,7 @@ The articles in this section describe Microsoft C/C++ compiler warning messages
|[Compiler warning (level 1) C4537](compiler-warning-level-1-c4537.md)|'*object*': '`.`' applied to non-UDT type|
|[Compiler warning (level 3) C4538](compiler-warning-level-3-c4538.md)|'*type*': `const`/`volatile` qualifiers on this type are not supported|
|[Compiler warning (level 1) C4540](compiler-warning-level-1-c4540.md)|`dynamic_cast` used to convert to inaccessible or ambiguous base; run-time test will fail ('*type1*' to '*type2*')|
|[Compiler warning (level 1) C4541](compiler-warning-level-1-c4541.md)|'*identifier*' used on polymorphic type '*type*' with `/GR-`; unpredictable behavior may result|
|[Compiler warning (level 1) C4541](compiler-warning-level-1-c4541.md)|'*operator*' used on polymorphic type '*type*' with /GR-; unpredictable behavior may result|
|Compiler warning (level 1) C4542|Skipping generation of merged injected text file, cannot write *filetype* file: '*issue*': *message*|
|[Compiler warning (level 3) C4543](compiler-warning-level-3-c4543.md)|Injected text suppressed by attribute '`no_injected_text`'|
|[Compiler warning (level 1) C4544](compiler-warning-level-1-c4544.md)|the default template argument for '*declaration*' is ignored on this template declaration|
Expand Down