Revert "Enable unnecessary-virtual-specifier by default" (#134105)

Reverts llvm/llvm-project#133265

This causes the whole libc++ CI to fail, since we're not building
against a compiler built from current trunk. Specifically, the CMake
changes causes some feature detection to fail, resulting in CMake
being unable to configure libc++.
This commit is contained in:
Nikolas Klauser 2025-04-02 17:59:08 +02:00 committed by GitHub
parent ee60f7c7a4
commit 04676c6160
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 9 additions and 16 deletions

View File

@ -377,12 +377,13 @@ def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
def WarnUnnecessaryVirtualSpecifier : DiagGroup<"unnecessary-virtual-specifier"> {
code Documentation = [{
Warns when a ``final`` class contains a virtual method (including virtual
destructors) that does not override anything. Since ``final`` classes cannot be
subclassed, their methods cannot be overridden, so there is no point to
introducing new ``virtual`` methods.
destructors). Since ``final`` classes cannot be subclassed, their methods
cannot be overridden, and hence the ``virtual`` specifier is useless.
The warning also detects virtual methods in classes whose destructor is
``final``, for the same reason.
The warning does not fire on virtual methods which are also marked ``override``.
}];
}

View File

@ -2733,7 +2733,7 @@ def note_final_dtor_non_final_class_silence : Note<
"mark %0 as '%select{final|sealed}1' to silence this warning">;
def warn_unnecessary_virtual_specifier : Warning<
"virtual method %0 is inside a 'final' class and can never be overridden">,
InGroup<WarnUnnecessaryVirtualSpecifier>;
InGroup<WarnUnnecessaryVirtualSpecifier>, DefaultIgnore;
// C++11 attributes
def err_repeat_attribute : Error<"%0 attribute cannot be repeated">;

View File

@ -1,4 +1,4 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -verify %s -Wno-unnecessary-virtual-specifier
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -verify %s
#include "mock-types.h"

View File

@ -28,7 +28,7 @@ struct C : A<int> { }; // expected-error {{base 'A' is marked 'final'}}
namespace Test4 {
struct A final { virtual void func() = 0; }; // expected-warning {{abstract class is marked 'final'}} expected-note {{unimplemented pure virtual method 'func' in 'A'}} expected-warning {{virtual method 'func' is inside a 'final' class}}}
struct A final { virtual void func() = 0; }; // expected-warning {{abstract class is marked 'final'}} expected-note {{unimplemented pure virtual method 'func' in 'A'}}
struct B { virtual void func() = 0; }; // expected-note {{unimplemented pure virtual method 'func' in 'C'}}
struct C final : B { }; // expected-warning {{abstract class is marked 'final'}}

View File

@ -470,7 +470,6 @@ struct InheritFromSealed : SealedType {};
class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}}
// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
// expected-warning@-1 {{virtual method '~SealedDestructor' is inside a 'final' class}}
};
// expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}

View File

@ -1,6 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class -Wno-unnecessary-virtual-specifier
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wfinal-dtor-non-final-class -Wno-unnecessary-virtual-specifier \
// RUN: -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s -Wfinal-dtor-non-final-class
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -Wfinal-dtor-non-final-class -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
class A {
~A();

View File

@ -690,12 +690,6 @@ endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
append("-Werror=unguarded-availability-new" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 21.0)
# LLVM has a policy of including virtual "anchor" functions to control
# where the vtable is emitted. In `final` classes, these are exactly what
# this warning detects: unnecessary virtual methods.
append("-Wno-unnecessary-virtual-specifier" CMAKE_CXX_FLAGS)
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND LLVM_ENABLE_LTO)