[clang-tools-extra] r363712 - [clang-tidy] Split fuchsia-default-arguments

Julie Hockett via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 11:07:33 PDT 2019


Author: juliehockett
Date: Tue Jun 18 11:07:33 2019
New Revision: 363712

URL: http://llvm.org/viewvc/llvm-project?rev=363712&view=rev
Log:
[clang-tidy] Split fuchsia-default-arguments

Splits fuchsia-default-arguments check into two checks. fuchsia-default-arguments-calls warns if a function or method is called with default arguments. fuchsia-default-arguments-declarations warns if a function or method is declared with default parameters.

Committed on behalf of @diegoast (Diego Astiazarán).

Resolves b38051.

Differential Revision: https://reviews.llvm.org/D62437

Added:
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
    clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst
    clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst
    clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp
    clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
Removed:
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
    clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h
    clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst
    clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
    clang-tools-extra/trunk/docs/ReleaseNotes.rst
    clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=363712&r1=363711&r2=363712&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Tue Jun 18 11:07:33 2019
@@ -1,7 +1,8 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyFuchsiaModule
-  DefaultArgumentsCheck.cpp
+  DefaultArgumentsCallsCheck.cpp
+  DefaultArgumentsDeclarationsCheck.cpp
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
   OverloadedOperatorCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp Tue Jun 18 11:07:33 2019
@@ -0,0 +1,35 @@
+//===--- DefaultArgumentsCallsCheck.cpp - clang-tidy-----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DefaultArgumentsCallsCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+void DefaultArgumentsCallsCheck::registerMatchers(MatchFinder *Finder) {
+  // Calling a function which uses default arguments is disallowed.
+  Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this);
+}
+
+void DefaultArgumentsCallsCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *S = Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt");
+  if (!S)
+    return;
+
+  diag(S->getUsedLocation(),
+       "calling a function that uses a default argument is disallowed");
+  diag(S->getParam()->getBeginLoc(), "default parameter was declared here",
+       DiagnosticIDs::Note);
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h Tue Jun 18 11:07:33 2019
@@ -0,0 +1,34 @@
+//===--- DefaultArgumentsCallsCheck.h - clang-tidy --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Default arguments are not allowed in called functions.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-default-arguments-calls.html
+class DefaultArgumentsCallsCheck : public ClangTidyCheck {
+public:
+  DefaultArgumentsCallsCheck(StringRef Name, ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H

Removed: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp?rev=363711&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp (removed)
@@ -1,61 +0,0 @@
-//===--- DefaultArgumentsCheck.cpp - clang-tidy----------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "DefaultArgumentsCheck.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace fuchsia {
-
-void DefaultArgumentsCheck::registerMatchers(MatchFinder *Finder) {
-  // Calling a function which uses default arguments is disallowed.
-  Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this);
-  // Declaring default parameters is disallowed.
-  Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind("decl"), this);
-}
-
-void DefaultArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *S =
-          Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt")) {
-    diag(S->getUsedLocation(),
-         "calling a function that uses a default argument is disallowed");
-    diag(S->getParam()->getBeginLoc(), "default parameter was declared here",
-         DiagnosticIDs::Note);
-  } else if (const ParmVarDecl *D =
-          Result.Nodes.getNodeAs<ParmVarDecl>("decl")) {
-    SourceRange DefaultArgRange = D->getDefaultArgRange();
-
-    if (DefaultArgRange.getEnd() != D->getEndLoc()) {
-      return;
-    } else if (DefaultArgRange.getBegin().isMacroID()) {
-      diag(D->getBeginLoc(),
-           "declaring a parameter with a default argument is disallowed");
-    } else {
-      SourceLocation StartLocation =
-          D->getName().empty() ? D->getBeginLoc() : D->getLocation();
-
-      SourceRange RemovalRange(Lexer::getLocForEndOfToken(
-             StartLocation, 0,
-             *Result.SourceManager,
-             Result.Context->getLangOpts()
-           ),
-           DefaultArgRange.getEnd()
-         );
-
-      diag(D->getBeginLoc(),
-           "declaring a parameter with a default argument is disallowed")
-          << D << FixItHint::CreateRemoval(RemovalRange);
-    }
-  }
-}
-
-} // namespace fuchsia
-} // namespace tidy
-} // namespace clang

Removed: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h?rev=363711&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h (removed)
@@ -1,34 +0,0 @@
-//===--- DefaultArgumentsCheck.h - clang-tidy--------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
-
-#include "../ClangTidyCheck.h"
-
-namespace clang {
-namespace tidy {
-namespace fuchsia {
-
-/// Default arguments are not allowed in declared or called functions.
-///
-/// For the user-facing documentation see:
-/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-default-arguments.html
-class DefaultArgumentsCheck : public ClangTidyCheck {
-public:
-  DefaultArgumentsCheck(StringRef Name, ClangTidyContext *Context)
-      : ClangTidyCheck(Name, Context) {}
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-};
-
-} // namespace fuchsia
-} // namespace tidy
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp Tue Jun 18 11:07:33 2019
@@ -0,0 +1,54 @@
+//===--- DefaultArgumentsDeclarationsCheck.cpp - clang-tidy ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DefaultArgumentsDeclarationsCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+void DefaultArgumentsDeclarationsCheck::registerMatchers(MatchFinder *Finder) {
+  // Declaring default parameters is disallowed.
+  Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind("decl"), this);
+}
+
+void DefaultArgumentsDeclarationsCheck::check(
+    const MatchFinder::MatchResult &Result) {
+  const auto *D = Result.Nodes.getNodeAs<ParmVarDecl>("decl");
+  if (!D)
+    return;
+
+  SourceRange DefaultArgRange = D->getDefaultArgRange();
+
+  if (DefaultArgRange.getEnd() != D->getEndLoc())
+    return;
+
+  if (DefaultArgRange.getBegin().isMacroID()) {
+    diag(D->getBeginLoc(),
+         "declaring a parameter with a default argument is disallowed");
+    return;
+  }
+
+  SourceLocation StartLocation =
+      D->getName().empty() ? D->getBeginLoc() : D->getLocation();
+
+  SourceRange RemovalRange(
+      Lexer::getLocForEndOfToken(StartLocation, 0, *Result.SourceManager,
+                                 Result.Context->getLangOpts()),
+      DefaultArgRange.getEnd());
+
+  diag(D->getBeginLoc(),
+       "declaring a parameter with a default argument is disallowed")
+      << D << FixItHint::CreateRemoval(RemovalRange);
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h Tue Jun 18 11:07:33 2019
@@ -0,0 +1,34 @@
+//===--- DefaultArgumentsDeclarationsCheck.h - clang-tidy -------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Default parameters are not allowed in declared functions.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-default-parameters.html
+class DefaultArgumentsDeclarationsCheck : public ClangTidyCheck {
+public:
+  DefaultArgumentsDeclarationsCheck(StringRef Name, ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_DECLARATIONS_H

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=363712&r1=363711&r2=363712&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Tue Jun 18 11:07:33 2019
@@ -1,4 +1,4 @@
-//===--- FuchsiaTidyModule.cpp - clang-tidy--------------------------------===//
+//===--- FuchsiaTidyModule.cpp - clang-tidy -------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,8 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../google/UnnamedNamespaceInHeaderCheck.h"
-#include "DefaultArgumentsCheck.h"
+#include "DefaultArgumentsCallsCheck.h"
+#include "DefaultArgumentsDeclarationsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
 #include "RestrictSystemIncludesCheck.h"
@@ -28,8 +29,10 @@ namespace fuchsia {
 class FuchsiaModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-    CheckFactories.registerCheck<DefaultArgumentsCheck>(
-        "fuchsia-default-arguments");
+    CheckFactories.registerCheck<DefaultArgumentsCallsCheck>(
+        "fuchsia-default-arguments-calls");
+    CheckFactories.registerCheck<DefaultArgumentsDeclarationsCheck>(
+        "fuchsia-default-arguments-declarations");
     CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
         "fuchsia-header-anon-namespaces");
     CheckFactories.registerCheck<MultipleInheritanceCheck>(

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=363712&r1=363711&r2=363712&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Tue Jun 18 11:07:33 2019
@@ -125,6 +125,20 @@ Improvements to clang-tidy
   repeated branches in ``switch`` statements and indentical true and false
   branches in conditional operators.
 
+- New :doc:`fuchsia-default-arguments-calls
+  <clang-tidy/checks/fuchsia-default-arguments-calls>` check.
+
+  Warns if a function or method is called with default arguments.
+  This was previously done by `fuchsia-default-arguments check`, which has been
+  removed.
+
+- New :doc:`fuchsia-default-arguments-calls
+  <clang-tidy/checks/fuchsia-default-arguments-calls>` check.
+
+  Warns if a function or method is declared with default parameters.
+  This was previously done by `fuchsia-default-arguments check` check, which has
+  been removed.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   <clang-tidy/checks/google-readability-avoid-underscore-in-googletest-name>`
   check.
@@ -166,6 +180,14 @@ Improvements to clang-tidy
   which greatly reduces warnings related to loops which are unlikely to
   cause an actual functional bug.
 
+- The ‘fuchsia-default-arguments’ check has been removed.
+
+  Warnings of function or method calls and declarations with default arguments
+  were moved to :doc:`fuchsia-default-arguments-calls
+  <clang-tidy/checks/fuchsia-default-arguments-calls>` and
+  :doc:`fuchsia-default-arguments-calls
+  <clang-tidy/checks/fuchsia-default-arguments-calls>` checks respectively.
+
 - The :doc:`google-runtime-int <clang-tidy/checks/google-runtime-int>`
   check has been disabled in Objective-C++.
 

Added: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst (added)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst Tue Jun 18 11:07:33 2019
@@ -0,0 +1,22 @@
+.. title:: clang-tidy - fuchsia-default-arguments-calls
+
+fuchsia-default-arguments-calls
+===============================
+
+Warns if a function or method is called with default arguments.
+
+For example, given the declaration:
+
+.. code-block:: c++
+
+  int foo(int value = 5) { return value; }
+
+A function call expression that uses a default argument will be diagnosed.
+Calling it without defaults will not cause a warning:
+
+.. code-block:: c++
+
+  foo();  // warning
+  foo(0); // no warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md

Added: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst (added)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst Tue Jun 18 11:07:33 2019
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - fuchsia-default-arguments-declarations
+
+fuchsia-default-arguments-declarations
+======================================
+
+Warns if a function or method is declared with default parameters.
+
+For example, the declaration:
+
+.. code-block:: c++
+
+  int foo(int value = 5) { return value; }
+
+will cause a warning.
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md

Removed: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst?rev=363711&view=auto
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst (removed)
@@ -1,24 +0,0 @@
-.. title:: clang-tidy - fuchsia-default-arguments
-
-fuchsia-default-arguments
-=========================
-
-Warns if a function or method is declared or called with default arguments.
-
-For example, the declaration:
-
-.. code-block:: c++
-
-  int foo(int value = 5) { return value; }
-
-will cause a warning.
-
-A function call expression that uses a default argument will be diagnosed.
-Calling it without defaults will not cause a warning:
-
-.. code-block:: c++
-
-  foo();  // warning
-  foo(0); // no warning
-
-See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=363712&r1=363711&r2=363712&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Tue Jun 18 11:07:33 2019
@@ -124,7 +124,8 @@ Clang-Tidy Checks
    cppcoreguidelines-pro-type-vararg
    cppcoreguidelines-slicing
    cppcoreguidelines-special-member-functions
-   fuchsia-default-arguments
+   fuchsia-default-arguments-calls
+   fuchsia-default-arguments-declarations
    fuchsia-header-anon-namespaces (redirects to google-build-namespaces) <fuchsia-header-anon-namespaces>
    fuchsia-multiple-inheritance
    fuchsia-overloaded-operator

Added: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp Tue Jun 18 11:07:33 2019
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s fuchsia-default-arguments-calls %t
+
+int foo(int value = 5) { return value; }
+
+int f() {
+  foo();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
+  // CHECK-NOTES: [[@LINE-5]]:9: note: default parameter was declared here
+}
+
+int bar(int value) { return value; }
+
+int n() {
+  foo(0);
+  bar(0);
+}
+
+void x(int i = 12);
+
+struct S {
+  void x(int i);
+};
+
+void S::x(int i = 12) {}
+
+int main() {
+  S s;
+  s.x();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
+  // CHECK-NOTES: [[@LINE-6]]:11: note: default parameter was declared here
+  // CHECK-NEXT: void S::x(int i = 12) {}
+  x();
+  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments-calls]
+  // CHECK-NOTES: [[@LINE-16]]:8: note: default parameter was declared here
+  // CHECK-NEXT: void x(int i = 12);
+}

Added: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp?rev=363712&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp Tue Jun 18 11:07:33 2019
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s fuchsia-default-arguments-declarations %t
+
+int foo(int value = 5) { return value; }
+// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+// CHECK-FIXES: int foo(int value) { return value; }
+
+int bar(int value) { return value; }
+
+class Baz {
+public:
+  int a(int value = 5) { return value; }
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+  // CHECK-FIXES: int a(int value) { return value; }
+
+  int b(int value) { return value; }
+};
+
+class Foo {
+  // Fix should be suggested in declaration
+  int a(int value = 53);
+  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+  // CHECK-FIXES: int a(int value);
+};
+
+// Fix shouldn't be suggested in implementation
+int Foo::a(int value) {
+  return value;
+}
+
+// Elided functions
+void f(int = 5) {};
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+// CHECK-FIXES: void f(int) {};
+
+void g(int) {};
+
+// Should not suggest fix for macro-defined parameters
+#define D(val) = val
+
+void h(int i D(5));
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+// CHECK-FIXES-NOT: void h(int i);
+
+void x(int i);
+void x(int i = 12);
+// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+// CHECK-FIXES: void x(int i);
+
+void x(int i) {}
+
+struct S {
+  void x(int i);
+};
+
+void S::x(int i = 12) {}
+// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
+// CHECK-FIXES: void S::x(int i) {}

Removed: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp?rev=363711&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp (removed)
@@ -1,80 +0,0 @@
-// RUN: %check_clang_tidy %s fuchsia-default-arguments %t
-
-int foo(int value = 5) { return value; }
-// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-// CHECK-FIXES: int foo(int value) { return value; }
-
-int f() {
-  foo();
-  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NOTES: [[@LINE-7]]:9: note: default parameter was declared here
-}
-
-int bar(int value) { return value; }
-
-int n() {
-  foo(0);
-  bar(0);
-}
-
-class Baz {
-public:
-  int a(int value = 5) { return value; }
-  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-FIXES: int a(int value) { return value; }
-
-  int b(int value) { return value; }
-};
-
-class Foo {
-  // Fix should be suggested in declaration
-  int a(int value = 53);
-  // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-FIXES: int a(int value);
-};
-
-// Fix shouldn't be suggested in implementation
-int Foo::a(int value) {
-  return value;
-}
-
-// Elided functions
-void f(int = 5) {};
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-// CHECK-FIXES: void f(int) {};
-
-void g(int) {};
-
-// Should not suggest fix for macro-defined parameters
-#define D(val) = val
-
-void h(int i D(5));
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-// CHECK-FIXES-NOT: void h(int i);
-
-void x(int i);
-void x(int i = 12);
-// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-// CHECK-FIXES: void x(int i);
-
-void x(int i) {}
-
-struct S {
-  void x(int i);
-};
-
-void S::x(int i = 12) {}
-// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments]
-// CHECK-FIXES: void S::x(int i) {}
-
-int main() {
-  S s;
-  s.x();
-  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NOTES: [[@LINE-8]]:11: note: default parameter was declared here
-  // CHECK-NEXT: void S::x(int i = 12) {}
-  x();
-  // CHECK-NOTES: [[@LINE-1]]:3: warning: calling a function that uses a default argument is disallowed [fuchsia-default-arguments]
-  // CHECK-NOTES: [[@LINE-18]]:8: note: default parameter was declared here
-  // CHECK-NEXT: void x(int i = 12);
-}




More information about the cfe-commits mailing list