summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulie Hockett <juliehockett@google.com>2019-06-18 18:07:33 +0000
committerJulie Hockett <juliehockett@google.com>2019-06-18 18:07:33 +0000
commitd9b3d08a9a631639190933531057b00d94afb758 (patch)
treeb0890c4a9ca8e47d8ea368cf81309be299916c2a
parent76a149ef8187310a60fd20481fdb2a10c8ba968e (diff)
downloadbcm5719-llvm-d9b3d08a9a631639190933531057b00d94afb758.tar.gz
bcm5719-llvm-d9b3d08a9a631639190933531057b00d94afb758.zip
[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 llvm-svn: 363712
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt3
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp35
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h (renamed from clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.h)16
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp61
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp54
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h34
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp11
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst22
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst (renamed from clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments.rst)12
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst16
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/list.rst3
-rw-r--r--clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-calls.cpp36
-rw-r--r--clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp (renamed from clang-tools-extra/test/clang-tidy/fuchsia-default-arguments.cpp)39
13 files changed, 229 insertions, 113 deletions
diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
index b69a5c06470..30b319e7e5a 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
@@ -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
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp
new file mode 100644
index 00000000000..fa814b8c29a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp
@@ -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
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
index 8d26c35a6a9..18dfe0c9cf2 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.h
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h
@@ -1,4 +1,4 @@
-//===--- DefaultArgumentsCheck.h - clang-tidy--------------------*- C++ -*-===//
+//===--- 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.
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
+#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"
@@ -15,13 +15,13 @@ namespace clang {
namespace tidy {
namespace fuchsia {
-/// Default arguments are not allowed in declared or called functions.
+/// 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.html
-class DefaultArgumentsCheck : public ClangTidyCheck {
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-default-arguments-calls.html
+class DefaultArgumentsCallsCheck : public ClangTidyCheck {
public:
- DefaultArgumentsCheck(StringRef Name, ClangTidyContext *Context)
+ DefaultArgumentsCallsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -31,4 +31,4 @@ public:
} // namespace tidy
} // namespace clang
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_DEFAULT_ARGUMENTS_CALLS_H
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
deleted file mode 100644
index 7f83ac674de..00000000000
--- a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
+++ /dev/null
@@ -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
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
new file mode 100644
index 00000000000..926c8b426df
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp
@@ -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
diff --git a/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
new file mode 100644
index 00000000000..19f16e6b46f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h
@@ -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
diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index 034a30ea38d..c59ec85468c 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -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>(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index ed8f15295f8..1442c8e5894 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -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++.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst
index ab011bf345b..bc33ed10d8b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst
@@ -1,18 +1,16 @@
-.. title:: clang-tidy - fuchsia-default-arguments
+.. title:: clang-tidy - fuchsia-default-arguments-calls
-fuchsia-default-arguments
-=========================
+fuchsia-default-arguments-calls
+===============================
-Warns if a function or method is declared or called with default arguments.
+Warns if a function or method is called with default arguments.
-For example, the declaration:
+For example, given 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:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst
new file mode 100644
index 00000000000..774425e9867
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst
@@ -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
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 6661cafa0f3..cafc346d56e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -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
diff --git a/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-calls.cpp b/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-calls.cpp
new file mode 100644
index 00000000000..ed9079092f6
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-calls.cpp
@@ -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);
+}
diff --git a/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments.cpp b/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
index 23f269ad129..1fe7041e24c 100644
--- a/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments.cpp
+++ b/clang-tools-extra/test/clang-tidy/fuchsia-default-arguments-declarations.cpp
@@ -1,26 +1,15 @@
-// RUN: %check_clang_tidy %s fuchsia-default-arguments %t
+// 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]
+// 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 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-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; }
@@ -29,7 +18,7 @@ public:
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-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
// CHECK-FIXES: int a(int value);
};
@@ -40,7 +29,7 @@ int Foo::a(int 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-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) {};
@@ -49,12 +38,12 @@ void g(int) {};
#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-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]
+// 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) {}
@@ -64,17 +53,5 @@ struct S {
};
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-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) {}
-
-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);
-}
OpenPOWER on IntegriCloud