r341284 - Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement
Author: jonastoth Date: Sun Sep 2 02:04:51 2018 New Revision: 341284 URL: http://llvm.org/viewvc/llvm-project?rev=341284&view=rev Log: Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement Summary: See https://bugs.llvm.org/show_bug.cgi?id=38713 Patch by Owen Pan! Reviewers: djasper, klimek, sammccall Reviewed By: sammccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51294 Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=341284&r1=341283&r2=341284&view=diff == --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Sun Sep 2 02:04:51 2018 @@ -483,6 +483,12 @@ private: if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; +// default: in switch statement +if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) +return 0; +} if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=341284&r1=341283&r2=341284&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Sep 2 02:04:51 2018 @@ -999,6 +999,24 @@ TEST_F(FormatTest, FormatsSwitchStatemen " }\n" "});", getLLVMStyle())); + EXPECT_EQ("switch (n) {\n" +"case 0: {\n" +" return false;\n" +"}\n" +"default: {\n" +" return true;\n" +"}\n" +"}", +format("switch (n)\n" + "{\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + getLLVMStyle())); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51294: Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement
JonasToth added a comment. Commited for Owen in r341284. Repository: rC Clang https://reviews.llvm.org/D51294 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51294: Fix Bug 38713: clang-format mishandles a short block after "default:" in a switch statement
This revision was automatically updated to reflect the committed changes. Closed by commit rL341284: Fix Bug 38713: clang-format mishandles a short block after "default:" in a… (authored by JonasToth, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D51294?vs=162989&id=163639#toc Repository: rL LLVM https://reviews.llvm.org/D51294 Files: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp === --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp @@ -483,6 +483,12 @@ if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; +// default: in switch statement +if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) +return 0; +} if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -999,6 +999,24 @@ " }\n" "});", getLLVMStyle())); + EXPECT_EQ("switch (n) {\n" +"case 0: {\n" +" return false;\n" +"}\n" +"default: {\n" +" return true;\n" +"}\n" +"}", +format("switch (n)\n" + "{\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + getLLVMStyle())); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n" Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp === --- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp +++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp @@ -483,6 +483,12 @@ if (Line.First->isOneOf(tok::kw_else, tok::kw_case) || (Line.First->Next && Line.First->Next->is(tok::kw_else))) return 0; +// default: in switch statement +if (Line.First->is(tok::kw_default)) { + const FormatToken *Tok = Line.First->getNextNonComment(); + if (Tok && Tok->is(tok::colon)) +return 0; +} if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try, tok::kw___try, tok::kw_catch, tok::kw___finally, tok::kw_for, tok::r_brace, Keywords.kw___except)) { Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -999,6 +999,24 @@ " }\n" "});", getLLVMStyle())); + EXPECT_EQ("switch (n) {\n" +"case 0: {\n" +" return false;\n" +"}\n" +"default: {\n" +" return true;\n" +"}\n" +"}", +format("switch (n)\n" + "{\n" + "case 0: {\n" + " return false;\n" + "}\n" + "default: {\n" + " return true;\n" + "}\n" + "}", + getLLVMStyle())); verifyFormat("switch (a) {\n" "case (b):\n" " return;\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51576: Enable DWARF accelerator tables by default when tuning for lldb (-glldb => -gpubnames)
labath created this revision. labath added a reviewer: dblaikie. DWARF v5 accelerator tables provide a considerable performance improvement for lldb and will make the default -glldb behavior same on all targets (right now we emit apple tables on apple targets, but these are not controlled by -gpubnames, only by -glldb). Repository: rC Clang https://reviews.llvm.org/D51576 Files: lib/Driver/ToolChains/Clang.cpp test/Driver/debug-options.c Index: test/Driver/debug-options.c === --- test/Driver/debug-options.c +++ test/Driver/debug-options.c @@ -165,6 +165,9 @@ // RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s // RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s // +// RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=GPUB %s +// RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s +// // RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s // // RUN: %clang -### -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 \ Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3072,7 +3072,7 @@ const auto *PubnamesArg = Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames, options::OPT_gpubnames, options::OPT_gno_pubnames); - if (SplitDWARFArg || + if (SplitDWARFArg || DebuggerTuning == llvm::DebuggerKind::LLDB || (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC))) if (!PubnamesArg || (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) && Index: test/Driver/debug-options.c === --- test/Driver/debug-options.c +++ test/Driver/debug-options.c @@ -165,6 +165,9 @@ // RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s // RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s // +// RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=GPUB %s +// RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s +// // RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s // // RUN: %clang -### -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 \ Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3072,7 +3072,7 @@ const auto *PubnamesArg = Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames, options::OPT_gpubnames, options::OPT_gno_pubnames); - if (SplitDWARFArg || + if (SplitDWARFArg || DebuggerTuning == llvm::DebuggerKind::LLDB || (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC))) if (!PubnamesArg || (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) && ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
Eugene.Zelenko added inline comments. Comment at: docs/ReleaseNotes.rst:60 +- New :doc:`google-objc-function-naming + ` check. Please use alphabetical order. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51575 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
stephanemoore updated this revision to Diff 163647. stephanemoore added a comment. Fixed alphabetical ordering of clang-tidy improvements in release notes. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51575 Files: clang-tidy/google/CMakeLists.txt clang-tidy/google/FunctionNamingCheck.cpp clang-tidy/google/FunctionNamingCheck.h clang-tidy/google/GoogleTidyModule.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/google-objc-function-naming.rst docs/clang-tidy/checks/list.rst test/clang-tidy/google-objc-function-naming.m unittests/clang-tidy/GoogleModuleTest.cpp Index: unittests/clang-tidy/GoogleModuleTest.cpp === --- unittests/clang-tidy/GoogleModuleTest.cpp +++ unittests/clang-tidy/GoogleModuleTest.cpp @@ -1,6 +1,7 @@ #include "ClangTidyTest.h" #include "google/ExplicitConstructorCheck.h" #include "google/GlobalNamesInHeadersCheck.h" +#include "google/FunctionNamingCheck.h" #include "gtest/gtest.h" using namespace clang::tidy::google; @@ -105,6 +106,28 @@ EXPECT_FALSE(runCheckOnCode("namespace {}", "foo.h")); } +TEST(ObjCFunctionNaming, AllowedStaticFunctionName) { + std::vector Errors; + runCheckOnCode( + "static void FooBar(void) {}", + &Errors, + "input.m"); + EXPECT_EQ(0ul, Errors.size()); +} + +TEST(ObjCFunctionNaming, LowerCamelCaseStaticFunctionName) { + std::vector Errors; + runCheckOnCode( + "static void fooBar(void) {}\n", + &Errors, + "input.m"); + EXPECT_EQ(1ul, Errors.size()); + EXPECT_EQ( + "function name 'fooBar' not using function naming conventions described by " + "Google Objective-C style guide", + Errors[0].Message.Message); +} + } // namespace test } // namespace tidy } // namespace clang Index: test/clang-tidy/google-objc-function-naming.m === --- /dev/null +++ test/clang-tidy/google-objc-function-naming.m @@ -0,0 +1,43 @@ +// RUN: %check_clang_tidy %s google-objc-function-naming %t + +typedef _Bool bool; + +static bool ispositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'ispositive' not using function naming conventions described by Google Objective-C style guide + +static bool is_positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'is_positive' not using function naming conventions described by Google Objective-C style guide + +static bool isPositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'isPositive' not using function naming conventions described by Google Objective-C style guide + +static bool Is_Positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'Is_Positive' not using function naming conventions described by Google Objective-C style guide + +static bool IsPositive(int a) { return a > 0; } + +static const char *md5(const char *str) { return 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function name 'md5' not using function naming conventions described by Google Objective-C style guide + +static const char *MD5(const char *str) { return 0; } + +static const char *URL(void) { return "https://clang.llvm.org/";; } + +static const char *DEFURL(void) { return "https://clang.llvm.org/";; } + +static const char *DEFFooURL(void) { return "https://clang.llvm.org/";; } + +static const char *StringFromNSString(id str) { return ""; } + +bool ispalindrome(const char *str); + +void ABLog_String(const char *str) {} +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ABLog_String' not using function naming conventions described by Google Objective-C style guide + +void ABLogString(const char *str) {} + +const char *ABURL(void) { return "https://clang.llvm.org/";; } + +const char *ABFooURL(void) { return "https://clang.llvm.org/";; } + +int main(int argc, const char **argv) { return 0; } Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -118,6 +118,7 @@ google-explicit-constructor google-global-names-in-headers google-objc-avoid-throwing-exception + google-objc-function-naming google-objc-global-variable-declaration google-readability-braces-around-statements (redirects to readability-braces-around-statements) google-readability-casting Index: docs/clang-tidy/checks/google-objc-function-naming.rst === --- /dev/null +++ docs/clang-tidy/checks/google-objc-function-naming.rst @@ -0,0 +1,29 @@ +.. title:: clang-tidy - google-objc-function-naming + +google-objc-function-naming +=== + +Finds function definitions in Objective-C files that do not follow the pattern +described in the Google Objective-C Style Guide. + +The corresponding style gui
[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
stephanemoore marked an inline comment as done. stephanemoore added inline comments. Comment at: docs/ReleaseNotes.rst:60 +- New :doc:`google-objc-function-naming + ` check. Eugene.Zelenko wrote: > Please use alphabetical order. Good catch. Fixed. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51575 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51533: [ASTImporter] Merge ExprBits
a_sidorin accepted this revision. a_sidorin added a comment. This revision is now accepted and ready to land. Looks good, thanks! Comment at: unittests/AST/ASTImporterTest.cpp:3241 + auto *ToD = Import(FromD, Lang_CXX11); + ASSERT_TRUE(ToD); + auto *ToInitExpr = cast(ToD)->getAnyInitializer(); EXPECT_TRUE (same below). Repository: rC Clang https://reviews.llvm.org/D51533 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51545: Enable -Wtautological-unsigned-zero-compare under -Wextra
thakis added a comment. We don't match gcc's -Wextra behvior. We generally try to not put a ton of stuff in Wextra that isn't in -Wall. (We also generally don't put a lot of stuff in -Wall that isn't enabled by default.) So I don't think we want this. https://reviews.llvm.org/D51545 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51580: (WIP) fix spurious exception spec error, PR38627
elsteveogrande created this revision. Herald added a subscriber: cfe-commits. Repository: rC Clang https://reviews.llvm.org/D51580 Files: test/Modules/Inputs/lax-base-except/a.h test/Modules/Inputs/lax-base-except/module.modulemap test/Modules/lax-base-except.cpp Index: test/Modules/lax-base-except.cpp === --- /dev/null +++ test/Modules/lax-base-except.cpp @@ -0,0 +1,10 @@ +// RUN: rm -rf %t +// RUN: %clang -c -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/lax-base-except %s -o %t2.o +// expected-no-diagnostics + +#include "a.h" + +class D : public A, public B { + public: + virtual ~D() override = default; +}; Index: test/Modules/Inputs/lax-base-except/module.modulemap === --- /dev/null +++ test/Modules/Inputs/lax-base-except/module.modulemap @@ -0,0 +1,3 @@ +module a { + header "a.h" +} Index: test/Modules/Inputs/lax-base-except/a.h === --- /dev/null +++ test/Modules/Inputs/lax-base-except/a.h @@ -0,0 +1,18 @@ +class A { + public: + virtual ~A() = default; +}; + +class B { + public: + virtual ~B() { +c.func(); + } + + struct C{ +void func() {} +friend B::~B(); + }; + + C c; +}; Index: test/Modules/lax-base-except.cpp === --- /dev/null +++ test/Modules/lax-base-except.cpp @@ -0,0 +1,10 @@ +// RUN: rm -rf %t +// RUN: %clang -c -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/lax-base-except %s -o %t2.o +// expected-no-diagnostics + +#include "a.h" + +class D : public A, public B { + public: + virtual ~D() override = default; +}; Index: test/Modules/Inputs/lax-base-except/module.modulemap === --- /dev/null +++ test/Modules/Inputs/lax-base-except/module.modulemap @@ -0,0 +1,3 @@ +module a { + header "a.h" +} Index: test/Modules/Inputs/lax-base-except/a.h === --- /dev/null +++ test/Modules/Inputs/lax-base-except/a.h @@ -0,0 +1,18 @@ +class A { + public: + virtual ~A() = default; +}; + +class B { + public: + virtual ~B() { +c.func(); + } + + struct C{ +void func() {} +friend B::~B(); + }; + + C c; +}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50958: [clangd] Implement findReferences function
hokein updated this revision to Diff 163654. hokein edited the summary of this revision. hokein added a comment. Rebase Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D50958 Files: clangd/XRefs.cpp clangd/XRefs.h unittests/clangd/XRefsTests.cpp Index: unittests/clangd/XRefsTests.cpp === --- unittests/clangd/XRefsTests.cpp +++ unittests/clangd/XRefsTests.cpp @@ -26,6 +26,7 @@ using namespace llvm; namespace { +using testing::_; using testing::ElementsAre; using testing::Field; using testing::IsEmpty; @@ -1068,6 +1069,179 @@ ElementsAre(Location{FooCppUri, FooWithoutHeader.range()})); } +TEST(FindReferences, AllWithoutIndex) { + const char *Tests[] = { + R"cpp(// Local variable +int main() { + int $foo[[foo]]; + $foo[[^foo]] = 2; + int test1 = $foo[[foo]]; +} + )cpp", + + R"cpp(// Struct +namespace ns1 { +struct $foo[[Foo]] {}; +} // namespace ns1 +int main() { + ns1::$foo[[Fo^o]]* Params; +} + )cpp", + + R"cpp(// Function +int $foo[[foo]](int) {} +int main() { + auto *X = &$foo[[^foo]]; + $foo[[foo]](42) +} + )cpp", + + R"cpp(// Field +struct Foo { + int $foo[[foo]]; + Foo() : $foo[[foo]](0) {} +}; +int main() { + Foo f; + f.$foo[[f^oo]] = 1; +} + )cpp", + + R"cpp(// Method call +struct Foo { int [[foo]](); }; +int Foo::[[foo]]() {} +int main() { + Foo f; + f.^foo(); +} + )cpp", + + R"cpp(// Typedef +typedef int $foo[[Foo]]; +int main() { + $foo[[^Foo]] bar; +} + )cpp", + + R"cpp(// Namespace +namespace $foo[[ns]] { +struct Foo {}; +} // namespace ns +int main() { $foo[[^ns]]::Foo foo; } + )cpp", + }; + for (const char *Test : Tests) { +Annotations T(Test); +auto AST = TestTU::withCode(T.code()).build(); +std::vector> ExpectedLocations; +for (const auto &R : T.ranges("foo")) + ExpectedLocations.push_back(RangeIs(R)); +EXPECT_THAT(findReferences(AST, T.point()), +ElementsAreArray(ExpectedLocations)) +<< Test; + } +} + +class MockIndex : public SymbolIndex { +public: + MOCK_CONST_METHOD2(fuzzyFind, bool(const FuzzyFindRequest &, + llvm::function_ref)); + MOCK_CONST_METHOD2(lookup, void(const LookupRequest &, + llvm::function_ref)); + MOCK_CONST_METHOD2(findOccurrences, + void(const OccurrencesRequest &, + llvm::function_ref)); + MOCK_CONST_METHOD0(estimateMemoryUsage, size_t()); +}; + +TEST(FindReferences, QueryIndex) { + const char *Tests[] = { + // Refers to symbols from headers. + R"cpp( +int main() { + F^oo foo; +} + )cpp", + R"cpp( +int main() { + f^unc(); +} + )cpp", + R"cpp( +int main() { + return I^NT; +} + )cpp", + + // These are cases of file-local but not function-local symbols, we still + // query the index. + R"cpp( +void MyF^unc() {} + )cpp", + + R"cpp( +int My^Int = 2; + )cpp", + }; + + TestTU TU; + TU.HeaderCode = R"( + class Foo {}; + static const int INT = 3; + inline void func() {}; + )"; + MockIndex Index; + for (const char *Test : Tests) { +Annotations T(Test); +TU.Code = T.code(); +auto AST = TU.build(); +EXPECT_CALL(Index, findOccurrences(_, _)); +findReferences(AST, T.point(), &Index); + } +} + +TEST(FindReferences, DontQueryIndex) { + // Don't query index for function-local symbols. + const char *Tests[] = { + R"cpp(// Local variable in function body +int main() { + int $foo[[foo]]; + $foo[[^foo]] = 2; +} + )cpp", + + R"cpp(// function parameter +int f(int fo^o) { +} + )cpp", + + R"cpp(// function parameter in lambda +int f(int foo) { + auto func = [](int a, int b) { +return ^a = 2; + }; +} + )cpp", + + R"cpp(// capture in lambda +int f(int foo) { + int A; + auto func = [&A](int a, int b) { +return a = ^A; + }; +} + )cpp", + }; + + MockIndex Index; + for (const char *Test : Tests) { +Annotations T(Test); +auto AST = TestTU::withCode(T.code()).build(); +EXPECT_CALL(Index, findOccurrences(_, _)).Times(0); +findReferences(AST, T.point(), &Index); + } +} + } // namespace } // namespace clangd } // namespace clang Index: clangd/XRefs.h === --- clangd/XRefs.h +++ clangd/XRefs.h @
[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
hokein added a comment. Nice! looks mostly good to me. Comment at: clang-tidy/google/FunctionNamingCheck.cpp:57 + functionDecl( + isDefinition(), + unless(anyOf(isMain(), matchesName(validFunctionNameRegex(true)), any reason why we restrict to definitions only? I think we can consider declarations too. Comment at: unittests/clang-tidy/GoogleModuleTest.cpp:109 +TEST(ObjCFunctionNaming, AllowedStaticFunctionName) { + std::vector Errors; nit: we don't need unittest for the check here, as it is well covered in the littest. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51575 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51575: [clang-tidy] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
stephanemoore updated this revision to Diff 163656. stephanemoore marked an inline comment as done. stephanemoore added a comment. Updated with changes: - Removed unit tests as other tests have been indicated to provide adequate coverage. - Added a comment explaining why only function definitions are evaluated. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51575 Files: clang-tidy/google/CMakeLists.txt clang-tidy/google/FunctionNamingCheck.cpp clang-tidy/google/FunctionNamingCheck.h clang-tidy/google/GoogleTidyModule.cpp docs/ReleaseNotes.rst docs/clang-tidy/checks/google-objc-function-naming.rst docs/clang-tidy/checks/list.rst test/clang-tidy/google-objc-function-naming.m Index: test/clang-tidy/google-objc-function-naming.m === --- /dev/null +++ test/clang-tidy/google-objc-function-naming.m @@ -0,0 +1,43 @@ +// RUN: %check_clang_tidy %s google-objc-function-naming %t + +typedef _Bool bool; + +static bool ispositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'ispositive' not using function naming conventions described by Google Objective-C style guide + +static bool is_positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'is_positive' not using function naming conventions described by Google Objective-C style guide + +static bool isPositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'isPositive' not using function naming conventions described by Google Objective-C style guide + +static bool Is_Positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'Is_Positive' not using function naming conventions described by Google Objective-C style guide + +static bool IsPositive(int a) { return a > 0; } + +static const char *md5(const char *str) { return 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function name 'md5' not using function naming conventions described by Google Objective-C style guide + +static const char *MD5(const char *str) { return 0; } + +static const char *URL(void) { return "https://clang.llvm.org/";; } + +static const char *DEFURL(void) { return "https://clang.llvm.org/";; } + +static const char *DEFFooURL(void) { return "https://clang.llvm.org/";; } + +static const char *StringFromNSString(id str) { return ""; } + +bool ispalindrome(const char *str); + +void ABLog_String(const char *str) {} +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ABLog_String' not using function naming conventions described by Google Objective-C style guide + +void ABLogString(const char *str) {} + +const char *ABURL(void) { return "https://clang.llvm.org/";; } + +const char *ABFooURL(void) { return "https://clang.llvm.org/";; } + +int main(int argc, const char **argv) { return 0; } Index: docs/clang-tidy/checks/list.rst === --- docs/clang-tidy/checks/list.rst +++ docs/clang-tidy/checks/list.rst @@ -118,6 +118,7 @@ google-explicit-constructor google-global-names-in-headers google-objc-avoid-throwing-exception + google-objc-function-naming google-objc-global-variable-declaration google-readability-braces-around-statements (redirects to readability-braces-around-statements) google-readability-casting Index: docs/clang-tidy/checks/google-objc-function-naming.rst === --- /dev/null +++ docs/clang-tidy/checks/google-objc-function-naming.rst @@ -0,0 +1,29 @@ +.. title:: clang-tidy - google-objc-function-naming + +google-objc-function-naming +=== + +Finds function definitions in Objective-C files that do not follow the pattern +described in the Google Objective-C Style Guide. + +The corresponding style guide rule can be found here: +https://google.github.io/styleguide/objcguide.html#function-names + +All function names should be in upper camel case. Functions whose storage class +is not static should have an appropriate prefix. + +The following code sample does not follow this pattern: + +.. code-block:: objc + + static bool is_positive(int i) { return i > 0; } + bool IsNegative(int i) { return i < 0; } + +The sample above might be corrected to the following code: + +.. code-block:: objc + + static bool IsPositive(int i) { return i > 0; } + bool *ABCIsNegative(int i) { return i < 0; } + +The check does not currently recommend any fixes. Index: docs/ReleaseNotes.rst === --- docs/ReleaseNotes.rst +++ docs/ReleaseNotes.rst @@ -93,6 +93,12 @@ Flags uses of ``absl::StrCat()`` to append to a ``std::string``. Suggests ``absl::StrAppend()`` should be used instead. +- New :doc:`google-objc-function-naming + ` check. + + Checks that function names in function definitions comply with the naming + conventi