Skip to content

Commit 322e4b4

Browse files
mikey dagitsespytorchmergebot
authored andcommitted
set -Wsuggest-override for builds (pytorch#89852)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/pytorch/pytorch/pull/89852). * __->__ pytorch#89852 * pytorch#89851 set -Wsuggest-override for builds Summary: This was flagged by a Meta internal build. Test Plan: Rely on CI. Pull Request resolved: pytorch#89852 Approved by: https://github.com/malfet
1 parent 8ecb49b commit 322e4b4

File tree

24 files changed

+96
-46
lines changed

24 files changed

+96
-46
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@ if(NOT MSVC)
848848
# Suppress "The ABI for passing parameters with 64-byte alignment has changed in GCC 4.6"
849849
string(APPEND CMAKE_CXX_FLAGS " -Wno-psabi")
850850
endif()
851+
if(NOT CMAKE_COMPILER_IS_GNUCXX OR GCC_VERSION VERSION_GREATER_EQUAL 9.2)
852+
# Prior to GCC 9.2, this warning misfires when a method is
853+
# labeled "final".
854+
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
855+
append_cxx_flag_if_supported("-Wsuggest-override" CMAKE_CXX_FLAGS)
856+
endif()
851857

852858
# Use ld.gold if available, fall back to ld.bfd (the default ld) if not
853859
if(USE_GOLD_LINKER)

aten/src/ATen/native/cudnn/Conv_v8.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
2+
23
#include <ATen/cuda/CUDAConfig.h> // for the definition of AT_CUDNN_ENABLED
34

45
#if AT_CUDNN_ENABLED()
@@ -8,7 +9,13 @@
89
#if HAS_CUDNN_V8()
910

1011
#include <ATen/cudnn/cudnn-wrapper.h>
12+
13+
#include <c10/macros/Macros.h>
14+
15+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wsuggest-override")
1116
#include <cudnn_frontend.h>
17+
C10_DIAGNOSTIC_POP()
18+
1219
#include <cudnn_frontend_find_plan.h>
1320
#include <cudnn_frontend_get_plan.h>
1421
#include <ATen/core/Tensor.h>

aten/src/ATen/native/quantized/cudnn/utils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ This file contains some of the auxiliary functions used by both Conv.cpp & Linea
1717
#include <ATen/native/quantized/PackedParams.h>
1818
#include <c10/core/QScheme.h>
1919
#include <c10/util/ArrayRef.h>
20+
21+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wsuggest-override")
2022
#include <cudnn_frontend.h>
23+
C10_DIAGNOSTIC_POP()
2124

2225
#ifndef AT_PER_OPERATOR_HEADERS
2326
#include <ATen/Functions.h>
@@ -118,7 +121,7 @@ struct PackedConvWeightCudnn : public ConvPackedParamsBase<kSpatialDim> {
118121

119122
at::Tensor apply_dynamic(
120123
const at::Tensor& input,
121-
bool reduce_range) {
124+
bool reduce_range) override {
122125
TORCH_CHECK(false, "apply_dynamic is currently not reported");
123126
}
124127

c10/macros/Macros.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,10 @@ __device__ __attribute__((noinline)) __attribute__((weak)) void __assert_fail(
512512
#endif
513513
#endif // HAS_DEMANGLE
514514

515-
#ifdef __clang__
516515
#define _C10_PRAGMA__(string) _Pragma(#string)
517516
#define _C10_PRAGMA_(string) _C10_PRAGMA__(string)
517+
518+
#ifdef __clang__
518519
#define C10_CLANG_DIAGNOSTIC_PUSH() _Pragma("clang diagnostic push")
519520
#define C10_CLANG_DIAGNOSTIC_POP() _Pragma("clang diagnostic pop")
520521
#define C10_CLANG_DIAGNOSTIC_IGNORE(flag) \
@@ -527,4 +528,29 @@ __device__ __attribute__((noinline)) __attribute__((weak)) void __assert_fail(
527528
#define C10_CLANG_HAS_WARNING(flag) 0
528529
#endif
529530

531+
#ifdef __clang__
532+
533+
#define C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED(warning) \
534+
_C10_PRAGMA_(clang diagnostic push) \
535+
_C10_PRAGMA_(clang diagnostic ignored "-Wunknown-warning-option") \
536+
_C10_PRAGMA_(clang diagnostic ignored warning)
537+
538+
#define C10_DIAGNOSTIC_POP() _C10_PRAGMA_(clang diagnostic pop)
539+
540+
#elif __GNUC__
541+
542+
#define C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED(warning) \
543+
_C10_PRAGMA_(GCC diagnostic push) \
544+
_C10_PRAGMA_(GCC diagnostic ignored "-Wpragmas") \
545+
_C10_PRAGMA_(GCC diagnostic ignored warning)
546+
547+
#define C10_DIAGNOSTIC_POP() _C10_PRAGMA_(GCC diagnostic pop)
548+
549+
#else
550+
551+
#define C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED(warning)
552+
#define C10_DIAGNOSTIC_POP()
553+
554+
#endif
555+
530556
#endif // C10_MACROS_MACROS_H_

test/cpp/api/dataloader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,12 +1050,10 @@ TEST(DataLoaderTest, MakeDataLoaderDefaultsAsExpected) {
10501050
}
10511051

10521052
struct UnsizedDataset : public datasets::Dataset<UnsizedDataset> {
1053-
// NOLINTNEXTLINE(cppcoreguidelines-explicit--functions,modernize-use-override)
1054-
torch::data::Example<> get(size_t i) {
1053+
torch::data::Example<> get(size_t i) override {
10551054
return {torch::ones(i), torch::ones(i)};
10561055
}
1057-
// NOLINTNEXTLINE(cppcoreguidelines-explicit--functions,modernize-use-override)
1058-
torch::optional<size_t> size() const noexcept {
1056+
torch::optional<size_t> size() const noexcept override {
10591057
return torch::nullopt;
10601058
}
10611059
};

test/cpp/dist_autograd/test_dist_autograd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DistAutogradTest : public ::testing::Test {
2020
autogradContainer_ = &DistAutogradContainer::init(0);
2121
}
2222

23-
virtual void TearDown() {
23+
void TearDown() override {
2424
autogradContainer_->releaseContext(
2525
autogradContainer_->currentContext()->contextId());
2626
}

test/cpp/jit/test_misc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,8 +3115,7 @@ TEST(TestShapeGraphLinting, Basic) {
31153115
// fusion parameters
31163116
class Composed : public ::testing::Test {
31173117
public:
3118-
// NOLINTNEXTLINE(modernize-use-override,cppcoreguidelines-explicit-virtual-functions)
3119-
void SetUp() {
3118+
void SetUp() override {
31203119
torch::jit::tensorexpr::getTEMustUseLLVMOnCPU() = false;
31213120
}
31223121
};

test/cpp/tensorexpr/test_graph_opt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ using namespace torch::jit::tensorexpr;
1818

1919
class GraphOpt : public ::testing::Test {
2020
public:
21-
// NOLINTNEXTLINE(modernize-use-override,cppcoreguidelines-explicit-virtual-functions)
22-
void SetUp() {
21+
void SetUp() override {
2322
old_cat_wo_conditionals_ = getCatWoConditionals();
2423
getCatWoConditionals() = true;
2524
}
2625

27-
void TearDown() {
26+
void TearDown() override {
2827
getCatWoConditionals() = old_cat_wo_conditionals_;
2928
}
3029

test/cpp/tensorexpr/test_kernel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ using namespace torch::jit::tensorexpr;
2424

2525
class Kernel : public ::testing::Test {
2626
public:
27-
// NOLINTNEXTLINE(modernize-use-override,cppcoreguidelines-explicit-virtual-functions)
28-
void SetUp() {
27+
void SetUp() override {
2928
getTEMustUseLLVMOnCPU() = false;
3029
}
3130
};

test/cpp/tensorexpr/test_loopnest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,8 +2292,7 @@ class LoopOrderHelper : public IRVisitor {
22922292
return ordering.str();
22932293
}
22942294

2295-
// NOLINTNEXTLINE(cppcoreguidelines-explicit--functions,modernize-use-override)
2296-
void visit(ForPtr v) {
2295+
void visit(ForPtr v) final {
22972296
ordering << v->var()->name_hint() << ",";
22982297
IRVisitor::visit(v);
22992298
}

0 commit comments

Comments
 (0)