[clang-tidy] Restrict use-equals-default to c++11-or-later
authorAlexander Shaposhnikov <ashaposhnikov@google.com>
Fri, 2 Sep 2022 22:19:06 +0000 (22:19 +0000)
committerAlexander Shaposhnikov <ashaposhnikov@google.com>
Fri, 2 Sep 2022 22:19:11 +0000 (22:19 +0000)
Restrict use-equals-default to c++11-or-later.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D132998

clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx98.cpp [new file with mode: 0644]

index a992177..4ffed8c 100644 (file)
@@ -38,7 +38,7 @@ class UseEqualsDefaultCheck : public ClangTidyCheck {
 public:
   UseEqualsDefaultCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
-    return LangOpts.CPlusPlus;
+    return LangOpts.CPlusPlus11;
   }
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
index 55c8c34..e0907b2 100644 (file)
@@ -145,7 +145,7 @@ Changes in existing checks
   check.
 
   The check now skips unions since in this case a default constructor with empty body
-  is not equivalent to the explicitly defaulted one.
+  is not equivalent to the explicitly defaulted one. The check is restricted to c++11-or-later.
 
 Removed checks
 ^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx98.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-cxx98.cpp
new file mode 100644 (file)
index 0000000..d43c1e5
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %check_clang_tidy -std=c++98 %s modernize-use-equals-default %t
+
+struct S {
+  S() {}
+  // CHECK-FIXES: S() {}
+  ~S() {}
+  // CHECK-FIXES: ~S() {}
+};