Index: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt +++ clang-tools-extra/trunk/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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h +++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.h @@ -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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCallsCheck.cpp +++ clang-tools-extra/trunk/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("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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h +++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.h @@ -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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsCheck.cpp @@ -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("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("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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.h +++ clang-tools-extra/trunk/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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/DefaultArgumentsDeclarationsCheck.cpp +++ clang-tools-extra/trunk/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("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 Index: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ clang-tools-extra/trunk/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 @@ class FuchsiaModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck( - "fuchsia-default-arguments"); + CheckFactories.registerCheck( + "fuchsia-default-arguments-calls"); + CheckFactories.registerCheck( + "fuchsia-default-arguments-declarations"); CheckFactories.registerCheck( "fuchsia-header-anon-namespaces"); CheckFactories.registerCheck( Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst @@ -125,6 +125,20 @@ repeated branches in ``switch`` statements and indentical true and false branches in conditional operators. +- New :doc:`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 + ` 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 ` check. @@ -166,6 +180,14 @@ 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 + ` and + :doc:`fuchsia-default-arguments-calls + ` checks respectively. + - The :doc:`google-runtime-int ` check has been disabled in Objective-C++. Index: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-calls.rst @@ -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 Index: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments-declarations.rst +++ clang-tools-extra/trunk/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 Index: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-default-arguments.rst @@ -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 Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst =================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst +++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst @@ -124,7 +124,8 @@ 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-multiple-inheritance fuchsia-overloaded-operator Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-calls.cpp +++ clang-tools-extra/trunk/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); +} Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp +++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments-declarations.cpp @@ -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) {} Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp +++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-default-arguments.cpp @@ -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); -}