File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -434,9 +434,9 @@ Improvements to Clang's diagnostics
434434- The ``-Wsign-compare `` warning now treats expressions with bitwise not(~) and minus(-) as signed integers
435435 except for the case where the operand is an unsigned integer
436436 and throws warning if they are compared with unsigned integers (##18878).
437- - The ``-Wunnecessary-virtual-specifier `` warning has been added to warn about
438- methods which are marked as virtual inside a `` final `` class, and hence can
439- never be overridden.
437+ - The ``-Wunnecessary-virtual-specifier `` warning (included in `` -Wextra ``) has
438+ been added to warn about methods which are marked as virtual inside a
439+ `` final `` class, and hence can never be overridden.
440440
441441- Improve the diagnostics for chained comparisons to report actual expressions and operators (#GH129069).
442442
Original file line number Diff line number Diff line change @@ -421,13 +421,12 @@ def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
421421def WarnUnnecessaryVirtualSpecifier : DiagGroup<"unnecessary-virtual-specifier"> {
422422 code Documentation = [{
423423Warns when a ``final`` class contains a virtual method (including virtual
424- destructors). Since ``final`` classes cannot be subclassed, their methods
425- cannot be overridden, and hence the ``virtual`` specifier is useless.
424+ destructors) that does not override anything. Since ``final`` classes cannot
425+ be subclassed, their methods cannot be overridden, so there is no point to
426+ introducing new ``virtual`` methods.
426427
427428The warning also detects virtual methods in classes whose destructor is
428429``final``, for the same reason.
429-
430- The warning does not fire on virtual methods which are also marked ``override``.
431430 }];
432431}
433432
@@ -1163,6 +1162,7 @@ def Extra : DiagGroup<"extra", [
11631162 FUseLdPath,
11641163 CastFunctionTypeMismatch,
11651164 InitStringTooLongMissingNonString,
1165+ WarnUnnecessaryVirtualSpecifier,
11661166 ]>;
11671167
11681168def Most : DiagGroup<"most", [
Original file line number Diff line number Diff line change @@ -882,6 +882,11 @@ if (LLVM_ENABLE_WARNINGS AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
882882 # The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful.
883883 append ("-Wno-noexcept-type" CMAKE_CXX_FLAGS )
884884
885+ # LLVM has a policy of including virtual "anchor" functions to control
886+ # where the vtable is emitted. In `final` classes, these are exactly what
887+ # this warning detects: unnecessary virtual methods.
888+ add_flag_if_supported("-Wno-unnecessary-virtual-specifier" CXX_SUPPORTS_UNNECESSARY_VIRTUAL_FLAG)
889+
885890 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
886891 append ("-Wnon-virtual-dtor" CMAKE_CXX_FLAGS )
887892 endif ()
You can’t perform that action at this time.
0 commit comments