Skip to content

Silence new warning C4877 when overriding deprecated non-pure virtual functions#6279

Open
StephanTLavavej wants to merge 2 commits into
microsoft:mainfrom
StephanTLavavej:wall-e
Open

Silence new warning C4877 when overriding deprecated non-pure virtual functions#6279
StephanTLavavej wants to merge 2 commits into
microsoft:mainfrom
StephanTLavavej:wall-e

Conversation

@StephanTLavavej
Copy link
Copy Markdown
Member

Example

C:\Temp>type meow.cpp
#include <__msvc_all_public_headers.hpp>

int main() {}

Before

C:\Temp>cl /EHsc /nologo /Wall /std:c++latest /MTd /Od /c meow.cpp
meow.cpp
D:\msvc\binaries\amd64chk\inc\xlocale(2321): warning C4877: overriding non-pure virtual function 'std::codecvt<char16_t,char,mbstate_t>::~codecvt': warning STL4020: std::codecvt<char16_t, char, mbstate_t>, std::codecvt<char32_t, char, mbstate_t>, std::codecvt_byname<char16_t, char, mbstate_t>, and std::codecvt_byname<char32_t, char, mbstate_t> are deprecated in C++20. You can define _SILENCE_CXX20_CODECVT_FACETS_DEPRECATION_WARNING or _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS to suppress this warning.
D:\msvc\binaries\amd64chk\inc\xlocale(2335): warning C4877: overriding non-pure virtual function 'std::codecvt<char32_t,char,mbstate_t>::~codecvt': warning STL4020: std::codecvt<char16_t, char, mbstate_t>, std::codecvt<char32_t, char, mbstate_t>, std::codecvt_byname<char16_t, char, mbstate_t>, and std::codecvt_byname<char32_t, char, mbstate_t> are deprecated in C++20. You can define _SILENCE_CXX20_CODECVT_FACETS_DEPRECATION_WARNING or _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS to suppress this warning.
D:\msvc\binaries\amd64chk\inc\xlocale(2350): warning C4877: overriding non-pure virtual function 'std::codecvt<char16_t,char8_t,mbstate_t>::~codecvt': warning STL4047: std::codecvt<char16_t, char8_t, mbstate_t>, std::codecvt<char32_t, char8_t, mbstate_t>, std::codecvt_byname<char16_t, char8_t, mbstate_t>, and std::codecvt_byname<char32_t, char8_t, mbstate_t> are deprecated by LWG-3767. You can define _SILENCE_CXX20_CODECVT_CHAR8_T_FACETS_DEPRECATION_WARNING or _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS to suppress this warning.
D:\msvc\binaries\amd64chk\inc\xlocale(2364): warning C4877: overriding non-pure virtual function 'std::codecvt<char32_t,char8_t,mbstate_t>::~codecvt': warning STL4047: std::codecvt<char16_t, char8_t, mbstate_t>, std::codecvt<char32_t, char8_t, mbstate_t>, std::codecvt_byname<char16_t, char8_t, mbstate_t>, and std::codecvt_byname<char32_t, char8_t, mbstate_t> are deprecated by LWG-3767. You can define _SILENCE_CXX20_CODECVT_CHAR8_T_FACETS_DEPRECATION_WARNING or _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS to suppress this warning.

For [[deprecated("reason")]], C4877 repeats the reason, otherwise it just says "was declared deprecated".

After

C:\Temp>cl /EHsc /nologo /Wall /std:c++latest /MTd /Od /c meow.cpp /I D:\GitHub\STL\stl\inc
meow.cpp

C:\Temp>

As we don't officially attempt to be /Wall-clean, we don't have /Wall test coverage, but the internal compiler selfbuild will be an effective test (after I remove the workaround in the compiler's sources).

Followup to GH 5645 on 2025-07-15.
…ING`.

Implemented by MSVC-PR-734301 on 2026-05-01.

Should revert selfbuild fix MSVC-PR-734920 on 2026-05-04.
Copilot AI review requested due to automatic review settings May 8, 2026 18:35
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner May 8, 2026 18:35
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label May 8, 2026
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews May 8, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Final Review in STL Code Reviews May 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the STL’s deprecated-warning suppression macro to also silence a newly introduced MSVC /Wall warning (C4877) that appears when overriding deprecated non-pure virtual functions.

Changes:

  • Clarify the classification comment for warning C5291 as /Wall-only.
  • Extend _STL_DISABLE_DEPRECATED_WARNING to disable C4877 in addition to C4996.
  • Add inline documentation describing C4877 and its relationship to C4996.
Show a summary per file
File Description
stl/inc/yvals_core.h Adds C4877 to the deprecated-warning suppression pragma and updates warning documentation comments.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread stl/inc/yvals_core.h
@StephanTLavavej StephanTLavavej moved this from Final Review to Ready To Merge in STL Code Reviews May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

Status: Ready To Merge

Development

Successfully merging this pull request may close these issues.

3 participants