From 3976b9ed0ce57ca059410509492fb8e9d6f0626e Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:16:46 +0800 Subject: [PATCH 1/4] Add blockquotes and update C4541 warning message --- .../compiler-warnings/compiler-warning-level-1-c4541.md | 2 +- .../compiler-warnings/compiler-warnings-c4400-through-c4599.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md index ed2547e029..f63a6f6f25 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md @@ -8,6 +8,6 @@ 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 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). diff --git a/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md b/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md index 03b421b60e..6bbc48d1b0 100644 --- a/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md +++ b/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md @@ -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| From f6f9a038ce525caf8fb91df58415a6482c46f4ed Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:38:45 +0800 Subject: [PATCH 2/4] Add "Remarks" heading and augment remarks in C4541 warning reference --- .../compiler-warnings/compiler-warning-level-1-c4541.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md index f63a6f6f25..07fdc9a778 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md @@ -10,4 +10,6 @@ ms.assetid: b57b8f3e-117d-4fc2-bba6-faec17e5fa9d > '*operator*' used on polymorphic type '*type*' with /GR-; unpredictable behavior may result -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). +## 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). From 5f5b299a555ad8486c8852a312cfd65a4ded7499 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:51:53 +0800 Subject: [PATCH 3/4] Add example in C4541 warning reference --- .../compiler-warning-level-1-c4541.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md index 07fdc9a778..0d7d7b7df5 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md @@ -13,3 +13,32 @@ ms.assetid: b57b8f3e-117d-4fc2-bba6-faec17e5fa9d ## 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 + +struct Base +{ + virtual ~Base() {} +}; + +struct Derived : Base {}; + +int main() +{ + Derived derived; + Base* pointer_to_base = &derived; + + dynamic_cast(pointer_to_base); // C4541 + + typeid(*pointer_to_base); // C4541 + typeid(pointer_to_base); // OK +} +``` From 04070b95593b5ee376e2d7fb52fba63ca61e67c1 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:53:33 +0800 Subject: [PATCH 4/4] Update metadata in 2 warning reference topics --- .../compiler-warnings/compiler-warning-level-1-c4541.md | 5 ++--- .../compiler-warnings-c4400-through-c4599.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md index 0d7d7b7df5..5b5982d38a 100644 --- a/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md +++ b/docs/error-messages/compiler-warnings/compiler-warning-level-1-c4541.md @@ -1,10 +1,9 @@ --- -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 diff --git a/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md b/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md index 6bbc48d1b0..e0ce42c253 100644 --- a/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md +++ b/docs/error-messages/compiler-warnings/compiler-warnings-c4400-through-c4599.md @@ -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"] ---