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
434
434
- The ``-Wsign-compare `` warning now treats expressions with bitwise not(~) and minus(-) as signed integers
435
435
except for the case where the operand is an unsigned integer
436
436
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.
440
440
441
441
- Improve the diagnostics for chained comparisons to report actual expressions and operators (#GH129069).
442
442
Original file line number Diff line number Diff line change @@ -421,13 +421,12 @@ def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
421
421
def WarnUnnecessaryVirtualSpecifier : DiagGroup<"unnecessary-virtual-specifier"> {
422
422
code Documentation = [{
423
423
Warns 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.
426
427
427
428
The warning also detects virtual methods in classes whose destructor is
428
429
``final``, for the same reason.
429
-
430
- The warning does not fire on virtual methods which are also marked ``override``.
431
430
}];
432
431
}
433
432
@@ -1163,6 +1162,7 @@ def Extra : DiagGroup<"extra", [
1163
1162
FUseLdPath,
1164
1163
CastFunctionTypeMismatch,
1165
1164
InitStringTooLongMissingNonString,
1165
+ WarnUnnecessaryVirtualSpecifier,
1166
1166
]>;
1167
1167
1168
1168
def 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))
882
882
# The LLVM libraries have no stable C++ API, so -Wnoexcept-type is not useful.
883
883
append ("-Wno-noexcept-type" CMAKE_CXX_FLAGS )
884
884
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
+
885
890
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
886
891
append ("-Wnon-virtual-dtor" CMAKE_CXX_FLAGS )
887
892
endif ()
0 commit comments