[PATCH] D130417: [clang-format] Missing space between trailing return type 'auto' and left brace

2022-07-28 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 448396.
denis-fatkulin added a comment.

Conflict with 'main' branch was solved


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130417/new/

https://reviews.llvm.org/D130417

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("[]() -> auto * { return Val; }", Style);
+  verifyFormat("[]() -> auto & { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto * { return Val; }", Style);
+  verifyFormat("auto foo() -> auto & { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("[]() -> auto * { return Val; }", Style);
+  verifyFormat("[]() -> auto & { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto * { return Val; }", Style);
+  verifyFormat("auto foo() -> auto & { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131088: [clang] Apply FixIts to members declared via `using` in derived classes

2022-08-03 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

FixIt don't switch to arrow in derrived members with `using`

Example code:

  struct Bar {
void foo();
  };
  struct Baz {
using Bar::foo;
  };
  void test(Baz* ptr) {
ptr.^
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131088

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:325:10 %s -o - | FileCheck 
-check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: 
{325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:331:10 %s -o - | FileCheck 
-check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: 
{331:8-331:9} to "->")
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1275,6 +1275,7 @@
 (R.Availability == CXAvailability_Available ||
  R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;
+Result.FixIts = R.FixIts;
 AddResult(Result, CurContext, Hiding);
 return;
   }
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -2184,6 +2184,42 @@
   EXPECT_TRUE(R.additionalTextEdits.empty());
 }
 
+TEST(CompletionTest, FixItForMembersUsing) {
+  const Annotations Code(R"cpp(
+struct Bar {
+void method();
+int field;
+  };
+  struct Baz : Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void foo(Baz* ptr) {
+ptr.m^ethod();
+ptr.f^ield;
+  }
+  )cpp");
+
+  TestTU TU;
+  TU.Code = Code.code().str();
+  auto CheckCompletion = [&TU](const Position &Pos, const std::string &Name) {
+clangd::CodeCompleteOptions Opts;
+Opts.IncludeFixIts = true;
+
+const auto Completions = completions(TU, Pos, {}, Opts).Completions;
+ASSERT_EQ(Completions.size(), 1u);
+EXPECT_EQ(Completions[0].Name, Name);
+
+const auto R = Completions[0].render(Opts);
+ASSERT_TRUE(R.textEdit);
+EXPECT_EQ(R.textEdit->newText, "->" + Name);
+  };
+
+  const auto Points = Code.points();
+  CheckCompletion(Points[0], "method");
+  CheckCompletion(Points[1], "field");
+}
+
 TEST(CompletionTest, RenderWithFixItNonMerged) {
   TextEdit FixIt;
   FixIt.range.end.character = 4;


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:325:10 %s -o - | FileCheck -check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: {325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:331:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {331:8-331:9} to "-

[PATCH] D131091: [clang][index] Index unresolved member expression as reference

2022-08-03 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
denis-fatkulin added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Unresolved member expressions aren't indexed as references.

Example code:

  struct Foo {
template  void $decl[[bar]](T t); 
  };
  template  void test(Foo F, T t) {
F.bar(t); // Not indexed
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131091

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp
  clang/test/Index/Core/index-dependent-source.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -392,6 +392,36 @@
 Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
WrittenAt(Position(4, 16));
 }
+
+TEST(IndexTest, UnresolvedLookupExpr) {
+  std::string Code = R"cpp(
+template  void foo(T t);
+template  void test(T t) {
+  foo(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 7);
+}
+
+TEST(IndexTest, UnresolvedMemberExpr) {
+  std::string Code = R"cpp(
+struct Foo {
+  template  void bar(T t);
+};
+template  void test(Foo F, T t) {
+  F.bar(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(6, 9);
+}
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-dependent-source.cpp
===
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -231,3 +231,12 @@
   foo();
 // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# |  | 
Ref,Call,RelCall,RelCont | rel: 1
 }
+
+struct Foo {
+  template  void bar();
+  // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | 
c:@S@Foo@FT@>1#Tbar#v# |  | Decl,RelChild | rel: 1
+};
+template  void baz(Foo f) {
+  f.bar();
+  // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# 
|  | Ref,Call,RelCall,RelCont | rel: 1
+}
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -468,7 +468,7 @@
 return true;
   }
 
-  bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+  bool VisitOverloadExpr(OverloadExpr *E) {
 SmallVector Relations;
 SymbolRoleSet Roles = getRolesForRef(E, Relations);
 for (auto *D : E->decls())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2090,6 +2090,14 @@
   [[f^oo]](s);
 }
   )cpp",
+  R"cpp(// unresolved member expression
+struct Foo {
+  template  void $decl[[bar]](T t); 
+};
+template  void test(Foo F, T t) {
+  F.[[b^ar]](t);
+}
+  )cpp",
 
   // Enum base
   R"cpp(


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -392,6 +392,36 @@
 Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
WrittenAt(Position(4, 16));
 }
+
+TEST(IndexTest, UnresolvedLookupExpr) {
+  std::string Code = R"cpp(
+template  void foo(T t);
+template  void test(T t) {
+  foo(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 7);
+}
+
+TEST(IndexTest, UnresolvedMemberExpr) {
+  std::string Code = R"cpp(
+struct Foo {
+  template  void bar(T t);
+};
+template  void test(Foo F, T t) {
+  F.bar(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference),
+ 

[PATCH] D131091: [clang][index] Index unresolved member expression as reference

2022-08-04 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 450111.
denis-fatkulin added a comment.

clangd unit test fixed


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131091/new/

https://reviews.llvm.org/D131091

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp
  clang/test/Index/Core/index-dependent-source.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -392,6 +392,36 @@
 Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
WrittenAt(Position(4, 16));
 }
+
+TEST(IndexTest, UnresolvedLookupExpr) {
+  std::string Code = R"cpp(
+template  void foo(T t);
+template  void test(T t) {
+  foo(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 7);
+}
+
+TEST(IndexTest, UnresolvedMemberExpr) {
+  std::string Code = R"cpp(
+struct Foo {
+  template  void bar(T t);
+};
+template  void test(Foo F, T t) {
+  F.bar(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(6, 9);
+}
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-dependent-source.cpp
===
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -231,3 +231,12 @@
   foo();
 // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# |  | 
Ref,Call,RelCall,RelCont | rel: 1
 }
+
+struct Foo {
+  template  void bar();
+  // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | 
c:@S@Foo@FT@>1#Tbar#v# |  | Decl,RelChild | rel: 1
+};
+template  void baz(Foo f) {
+  f.bar();
+  // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# 
|  | Ref,Call,RelCall,RelCont | rel: 1
+}
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -468,7 +468,7 @@
 return true;
   }
 
-  bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+  bool VisitOverloadExpr(OverloadExpr *E) {
 SmallVector Relations;
 SymbolRoleSet Roles = getRolesForRef(E, Relations);
 for (auto *D : E->decls())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2090,6 +2090,14 @@
   [[f^oo]](s);
 }
   )cpp",
+  R"cpp(// unresolved member expression
+struct Foo {
+  template  void $decl[[b^ar]](T t); 
+};
+template  void test(Foo F, T t) {
+  F.[[bar]](t);
+}
+  )cpp",
 
   // Enum base
   R"cpp(


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -392,6 +392,36 @@
 Contains(AllOf(QName("MyTypedef"), HasRole(SymbolRole::Reference),
WrittenAt(Position(4, 16));
 }
+
+TEST(IndexTest, UnresolvedLookupExpr) {
+  std::string Code = R"cpp(
+template  void foo(T t);
+template  void test(T t) {
+  foo(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("foo"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(4, 7);
+}
+
+TEST(IndexTest, UnresolvedMemberExpr) {
+  std::string Code = R"cpp(
+struct Foo {
+  template  void bar(T t);
+};
+template  void test(Foo F, T t) {
+  F.bar(t);
+}
+  )cpp";
+  auto Index = std::make_shared();
+  tooling::runToolOnCode(std::make_unique(Index), Code);
+  EXPECT_THAT(Index->Symbols,
+  Contains(AllOf(QName("Foo::bar"), HasRole(SymbolRole::Reference),
+ WrittenAt(Position(6, 9);
+}
 } // namespace
 } // namespace index
 } // namespace clang
Index: clang/test/Index/Core/index-dependent-source.cpp
===
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -23

[PATCH] D131088: [clang] Apply FixIts to members declared via `using` in derived classes

2022-08-08 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 450929.
denis-fatkulin added a comment.

Patch is updatetd according to remarks by @kadircet.

@kadircet, could you please also merge my pacth to code base? I haven't such 
permissions yet.
My git user name and address: Denis Fatkulin (fatkulin.de...@huawei.com)

Thank you for the review!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131088/new/

https://reviews.llvm.org/D131088

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:325:10 %s -o - | FileCheck 
-check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: 
{325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:331:10 %s -o - | FileCheck 
-check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: 
{331:8-331:9} to "->")
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1273,7 +1273,8 @@
 getBasePriority(Using->getTargetDecl()),
 R.Qualifier, false,
 (R.Availability == CXAvailability_Available ||
- R.Availability == CXAvailability_Deprecated));
+ R.Availability == CXAvailability_Deprecated),
+std::move(R.FixIts));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:325:10 %s -o - | FileCheck -check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: {325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:331:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {331:8-331:9} to "->")
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1273,7 +1273,8 @@
 getBasePriority(Using->getTargetDecl()),
 R.Qualifier, false,
 (R.Availability == CXAvailability_Available ||
- R.Availability == CXAvailability_Deprecated));
+ R.Availability == CXAvailability_Deprecated),
+std::move(R.FixIts));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131088: [clang] Apply FixIts to members declared via `using` in derived classes

2022-08-08 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin marked an inline comment as done.
denis-fatkulin added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:1276
 (R.Availability == CXAvailability_Available ||
  R.Availability == CXAvailability_Deprecated));
 Result.ShadowDecl = Using;

kadircet wrote:
> you can just pass `std::move(R.FixIts)` as the next argument in this 
> constructor call instead.
Fixed. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131088/new/

https://reviews.llvm.org/D131088

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131091: [clang][index] Index unresolved member expression as reference

2022-08-10 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 451624.
denis-fatkulin added a comment.

Broken tests are deleted


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131091/new/

https://reviews.llvm.org/D131091

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp
  clang/test/Index/Core/index-dependent-source.cpp


Index: clang/test/Index/Core/index-dependent-source.cpp
===
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -231,3 +231,12 @@
   foo();
 // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# |  | 
Ref,Call,RelCall,RelCont | rel: 1
 }
+
+struct Foo {
+  template  void bar();
+  // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | 
c:@S@Foo@FT@>1#Tbar#v# |  | Decl,RelChild | rel: 1
+};
+template  void baz(Foo f) {
+  f.bar();
+  // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# 
|  | Ref,Call,RelCall,RelCont | rel: 1
+}
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -468,7 +468,7 @@
 return true;
   }
 
-  bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+  bool VisitOverloadExpr(OverloadExpr *E) {
 SmallVector Relations;
 SymbolRoleSet Roles = getRolesForRef(E, Relations);
 for (auto *D : E->decls())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2090,6 +2090,14 @@
   [[f^oo]](s);
 }
   )cpp",
+  R"cpp(// unresolved member expression
+struct Foo {
+  template  void $decl[[b^ar]](T t); 
+};
+template  void test(Foo F, T t) {
+  F.[[bar]](t);
+}
+  )cpp",
 
   // Enum base
   R"cpp(


Index: clang/test/Index/Core/index-dependent-source.cpp
===
--- clang/test/Index/Core/index-dependent-source.cpp
+++ clang/test/Index/Core/index-dependent-source.cpp
@@ -231,3 +231,12 @@
   foo();
 // CHECK: [[@LINE-1]]:3 | function/C | foo | c:@FT@>1#Tfoo#v# |  | Ref,Call,RelCall,RelCont | rel: 1
 }
+
+struct Foo {
+  template  void bar();
+  // CHECK: [[@LINE-1]]:30 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# |  | Decl,RelChild | rel: 1
+};
+template  void baz(Foo f) {
+  f.bar();
+  // CHECK: [[@LINE-1]]:5 | instance-method/C++ | bar | c:@S@Foo@FT@>1#Tbar#v# |  | Ref,Call,RelCall,RelCont | rel: 1
+}
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -468,7 +468,7 @@
 return true;
   }
 
-  bool VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
+  bool VisitOverloadExpr(OverloadExpr *E) {
 SmallVector Relations;
 SymbolRoleSet Roles = getRolesForRef(E, Relations);
 for (auto *D : E->decls())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2090,6 +2090,14 @@
   [[f^oo]](s);
 }
   )cpp",
+  R"cpp(// unresolved member expression
+struct Foo {
+  template  void $decl[[b^ar]](T t); 
+};
+template  void test(Foo F, T t) {
+  F.[[bar]](t);
+}
+  )cpp",
 
   // Enum base
   R"cpp(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130299: [clang-format] FIX: Misformatting lambdas with trailing return type 'auto' in braced lists

2022-07-21 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
denis-fatkulin added a reviewer: rsmith.
denis-fatkulin added a project: clang-format.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Lambdas with trailing return type 'auto' are formatted incorrectly in braced 
lists. The simpliest reproduction code is:

  cpp
  auto list = {[]() -> auto { return 0; }};

Was reported at https://github.com/llvm/llvm-project/issues/54798


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130299

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23546,6 +23546,13 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23546,6 +23546,13 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130299: [clang-format] FIX: Misformatting lambdas with trailing return type 'auto' in braced lists

2022-07-22 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 446916.
denis-fatkulin added a comment.

> Could you please add full git context?

I updated the patch with properly git context. Thanks!

> Was the problem due to misannotation of auto? If so, could you add an 
> annotator test?

I'm not sure about the questions. I will try to explain my patch purpose. 
Actually there was two problems:

1. `auto` wasn't detected as properly type keyword in lambda's trailing return 
type. So, formatting was completely wrong for this case (fixed in 
`clang/lib/Format/UnwrappedLineParser.cpp`)
2. The keyword `auto` and left brace `{` was interpreted as declaration 
`auto{}`. So, formatting delete a space symbol between them. (fixed in 
`clang/lib/Format/TokenAnnotator.cpp`)

Both cases are checked in changes at `clang/unittests/Format/FormatTest.cpp` 
and I think the unit test is sufficient.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,13 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,13 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("auto list = {[]() -> auto { return Val; }};", Style);
+  verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style);
+  verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,10 @@
 }
   }
 
+  // Lambda with trailing return type 'auto': []() -> auto { return T; }
+  if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace)
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130299: [clang-format] FIX: Misannotation 'auto' as trailing return type in lambdas

2022-07-23 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 447052.
denis-fatkulin retitled this revision from "[clang-format] FIX: Misformatting 
lambdas with trailing return type 'auto' in braced lists" to "[clang-format] 
FIX: Misannotation 'auto' as trailing return type in lambdas".
denis-fatkulin edited the summary of this revision.
denis-fatkulin added a comment.

Patch is splitted, as suggested by @HazardyKnusperkeks

This piece of changes is related to misannotation KW 'auto' as trailing return 
type in lambdas. Also, appropriate test is added.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -749,6 +749,13 @@
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnTypeAutoInLabmdas) {
+  auto Tokens = annotate("[]() -> auto {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -749,6 +749,13 @@
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnTypeAutoInLabmdas) {
+  auto Tokens = annotate("[]() -> auto {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130417: [clang-format] Missing space between trailing return type 'auto' and left brace

2022-07-23 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
denis-fatkulin added reviewers: HazardyKnusperkeks, curdeius.
denis-fatkulin added a project: clang-format.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There's no a space symbol between  trailing return type `auto` and left brace 
`{`.

The simpliest examles of code to reproduce the issue:

  []() -> auto {}

and

  auto foo() -> auto {}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130417

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,12 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,12 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130299: [clang-format] FIX: Misannotation 'auto' as trailing return type in lambdas

2022-07-24 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 447115.
denis-fatkulin added a comment.

Test cases for `auto &` and `auto *` are added


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -747,6 +747,21 @@
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto & {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto * {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
 }
 
 } // namespace
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -747,6 +747,21 @@
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto & {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]() -> auto * {}");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
 }
 
 } // namespace
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2108,6 +2108,7 @@
 case tok::l_square:
   parseSquare();
   break;
+case tok::kw_auto:
 case tok::kw_class:
 case tok::kw_template:
 case tok::kw_typename:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130417: [clang-format] Missing space between trailing return type 'auto' and left brace

2022-07-24 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 447116.
denis-fatkulin added a comment.

Test cases for `auto &` and `auto *` are added


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130417/new/

https://reviews.llvm.org/D130417

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("[]() -> auto * { return Val; }", Style);
+  verifyFormat("[]() -> auto & { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto * { return Val; }", Style);
+  verifyFormat("auto foo() -> auto & { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23550,6 +23550,16 @@
   verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
 }
 
+TEST_F(FormatTest, TrailingReturnTypeAuto) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("[]() -> auto * { return Val; }", Style);
+  verifyFormat("[]() -> auto & { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto * { return Val; }", Style);
+  verifyFormat("auto foo() -> auto & { return Val; }", Style);
+}
+
 TEST_F(FormatTest, SpacesInConditionalStatement) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.IfMacros.clear();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3310,6 +3310,11 @@
 }
   }
 
+  // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
+  if (Left.is(tok::kw_auto) &&
+  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+return true;
+
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130299: [clang-format] FIX: Misannotation 'auto' as trailing return type in lambdas

2022-07-24 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin added a comment.

In D130299#3674586 , 
@HazardyKnusperkeks wrote:

> Do you have commit access, or do you want to apply for it, or do you need 
> someone to push the change(s)? If the latter we need a name and mail for the 
> commit.

I haven't access for merging changes to code base. So, I need support from 
community for doing this.

My name and mail:
Name: **Denis Fatkulin**
Mail: **fatkulin.de...@huawei.com**

Thank you!

PS. Related patch should be merged too. D130417 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130299/new/

https://reviews.llvm.org/D130299

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130417: [clang-format] Missing space between trailing return type 'auto' and left brace

2022-07-24 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin marked 2 inline comments as done.
denis-fatkulin added a comment.

They marked done. Thanks!




Comment at: clang/unittests/Format/FormatTest.cpp:23555-23556
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("[]() -> auto { return Val; }", Style);
+  verifyFormat("auto foo() -> auto { return Val; }", Style);
+}

curdeius wrote:
> owenpan wrote:
> > Should we add test cases with an `&` between `auto` and `{`?
> :+1:
Then it's better to add the case not only for `auto &`, but for `auto *` too.
But actually these cases are hadled correctly without this patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130417/new/

https://reviews.llvm.org/D130417

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131088: [clang] Apply FixIts to members declared via `using` in derived classes

2022-08-13 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 452408.
denis-fatkulin added a comment.

Patch is updated with context


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131088/new/

https://reviews.llvm.org/D131088

Files:
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | 
FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:325:10 %s -o - | FileCheck 
-check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: 
{325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:331:10 %s -o - | FileCheck 
-check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: 
{331:8-331:9} to "->")
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1273,7 +1273,8 @@
 getBasePriority(Using->getTargetDecl()),
 R.Qualifier, false,
 (R.Availability == CXAvailability_Available ||
- R.Availability == CXAvailability_Deprecated));
+ R.Availability == CXAvailability_Deprecated),
+std::move(R.FixIts));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;


Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -311,3 +311,25 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:310:19 %s -o - | FileCheck -check-prefix=CHECK-MEMBERS-FROM-BASE-DEPENDENT %s
   // CHECK-MEMBERS-FROM-BASE-DEPENDENT: [#Base4#]base4
 }
+
+namespace members_using_fixits {
+  struct Bar {
+void method();
+int field;
+  };
+  struct Baz: Bar {
+using Bar::method;
+using Bar::field;
+  };
+  void testMethod(Baz* ptr) {
+ptr.m
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:325:10 %s -o - | FileCheck -check-prefix=CHECK-METHOD-DECLARED-VIA-USING %s
+  // CHECK-METHOD-DECLARED-VIA-USING: [#void#]method() (requires fix-it: {325:8-325:9} to "->")
+
+  void testField(Baz* ptr) {
+ptr.f
+  }
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:331:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
+  // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {331:8-331:9} to "->")
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1273,7 +1273,8 @@
 getBasePriority(Using->getTargetDecl()),
 R.Qualifier, false,
 (R.Availability == CXAvailability_Available ||
- R.Availability == CXAvailability_Deprecated));
+ R.Availability == CXAvailability_Deprecated),
+std::move(R.FixIts));
 Result.ShadowDecl = Using;
 AddResult(Result, CurContext, Hiding);
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131091: [clang][index] Index unresolved member expression as reference

2022-08-13 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin added a comment.

@hokein, could you please also merge my pacth to code base? I haven't such 
permissions yet.
My git user name and address: Denis Fatkulin (fatkulin.de...@huawei.com)

Thank you for the review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131091/new/

https://reviews.llvm.org/D131091

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-09 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin created this revision.
denis-fatkulin added reviewers: kadircet, sammccall.
Herald added a subscriber: arphaman.
Herald added a project: All.
denis-fatkulin requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The refactoring !!Move function body to out-of-line!! produces incorrect code 
for methods of unnamed classes.
For this simple example

  // foo.h
  struct Foo {
struct {
  void f^oo() {}
} Bar;
  };

the refactoring generates code:

  // foo.cpp
  void Foo::(unnamed struct at D:\test\foo.h:2:3)foo() {}

Outplace definition for methods of unnamed classes is meaningless. The patch 
disables it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143638

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,23 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -397,6 +397,14 @@
 if (auto *MD = llvm::dyn_cast(Source)) {
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();
+  while (Parent) {
+if (Parent->getName().empty())
+  return false;
+Parent = llvm::dyn_cast_or_null(Parent->getParent());
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,23 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -397,6 +397,14 @@
 if (auto *MD = llvm::dyn_cast(Source)) {
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();
+  while (Parent) {
+if (Parent->getName().empty())
+  return false;
+Parent = llvm::dyn_cast_or_null(Parent->getParent());
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-10 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin updated this revision to Diff 496375.
denis-fatkulin added a comment.

Review fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143638/new/

https://reviews.llvm.org/D143638

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,32 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
+
+  // Not available on definitions within unnamed namespaces
+  EXPECT_UNAVAILABLE(R"cpp(
+namespace {
+  struct Foo {
+void f^oo() {}
+  };
+} // namespace
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -392,11 +392,20 @@
 if (Source->getTemplateSpecializationInfo())
   return false;
 
-// Bail out in templated classes, as it is hard to spell the class name, 
i.e
-// if the template parameter is unnamed.
 if (auto *MD = llvm::dyn_cast(Source)) {
+  // Bail out in templated classes, as it is hard to spell the class name,
+  // i.e if the template parameter is unnamed.
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes and definitions
+  // within unnamed namespaces.
+  for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
+if (auto *ND = llvm::dyn_cast(DC)) {
+  if (ND->getDeclName().isEmpty())
+return false;
+}
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,32 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
+
+  // Not available on definitions within unnamed namespaces
+  EXPECT_UNAVAILABLE(R"cpp(
+namespace {
+  struct Foo {
+void f^oo() {}
+  };
+} // namespace
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -392,11 +392,20 @@
 if (Source->getTemplateSpecializationInfo())
   return false;
 
-// Bail out in templated classes, as it is hard to spell the class name, i.e
-// if the template parameter is unnamed.
 if (auto *MD = llvm::dyn_cast(Source)) {
+  // Bail out in templated classes, as it is hard to spell the class name,
+  // i.e if the template parameter is unnamed.
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes and definitions
+  // within unnamed namespaces.
+  for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
+if (auto *ND = llvm::dyn_cast(DC)) {
+  if (ND->getDeclName().isEmpty())
+return false;
+}
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-10 Thread Denis Fatkulin via Phabricator via cfe-commits
denis-fatkulin marked 3 inline comments as done.
denis-fatkulin added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:395
 
 // Bail out in templated classes, as it is hard to spell the class name, 
i.e
 // if the template parameter is unnamed.

kadircet wrote:
> could you move this comment closer to the `isTempated` if statement below?
Fixed



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:401
+
+  // The refactoring is meaningless for unnamed classes.
+  const auto *Parent = MD->getParent();

kadircet wrote:
> not just classes, but also for cases with unnamed namespaces.
> 
> could you change this to look like:
> ```
> for(DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
>   if (auto *ND = llvm::dyn_cast(DC)) {
>  if(ND->getDeclName().isEmpty())
> return false;
>   }
> }
> ```
It's a useful remark. Tanks! 



Comment at: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp:97
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {

kadircet wrote:
> can you also have a test inside an unnamed namespace?
Test case added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143638/new/

https://reviews.llvm.org/D143638

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143638: [clangd] Move function body to out-of-line: unnamed class method incorrect moving

2023-02-10 Thread Denis Fatkulin via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
denis-fatkulin marked 3 inline comments as done.
Closed by commit rG04f4c4cc59db: [clangd] Move function body to out-of-line: 
unnamed class method incorrect… (authored by denis-fatkulin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143638/new/

https://reviews.llvm.org/D143638

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,32 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
+
+  // Not available on definitions within unnamed namespaces
+  EXPECT_UNAVAILABLE(R"cpp(
+namespace {
+  struct Foo {
+void f^oo() {}
+  };
+} // namespace
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -392,11 +392,20 @@
 if (Source->getTemplateSpecializationInfo())
   return false;
 
-// Bail out in templated classes, as it is hard to spell the class name, 
i.e
-// if the template parameter is unnamed.
 if (auto *MD = llvm::dyn_cast(Source)) {
+  // Bail out in templated classes, as it is hard to spell the class name,
+  // i.e if the template parameter is unnamed.
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes and definitions
+  // within unnamed namespaces.
+  for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
+if (auto *ND = llvm::dyn_cast(DC)) {
+  if (ND->getDeclName().isEmpty())
+return false;
+}
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -84,6 +84,32 @@
 template  void fo^o() {};
 template <> void fo^o() {};
   )cpp");
+
+  // Not available on methods of unnamed classes.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct { void b^ar() {} } Bar;
+};
+  )cpp");
+
+  // Not available on methods of named classes with unnamed parent in parents
+  // nesting.
+  EXPECT_UNAVAILABLE(R"cpp(
+struct Foo {
+  struct {
+struct Bar { void b^ar() {} };
+  } Baz;
+};
+  )cpp");
+
+  // Not available on definitions within unnamed namespaces
+  EXPECT_UNAVAILABLE(R"cpp(
+namespace {
+  struct Foo {
+void f^oo() {}
+  };
+} // namespace
+  )cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -392,11 +392,20 @@
 if (Source->getTemplateSpecializationInfo())
   return false;
 
-// Bail out in templated classes, as it is hard to spell the class name, i.e
-// if the template parameter is unnamed.
 if (auto *MD = llvm::dyn_cast(Source)) {
+  // Bail out in templated classes, as it is hard to spell the class name,
+  // i.e if the template parameter is unnamed.
   if (MD->getParent()->isTemplated())
 return false;
+
+  // The refactoring is meaningless for unnamed classes and definitions
+  // within unnamed namespaces.
+  for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
+if (auto *ND = llvm::dyn_cast(DC)) {
+  if (ND->getDeclName().isEmpty())
+return false;
+}
+  }
 }
 
 // Note that we don't check whether an implementation file exists or not in
___
cfe-commits mailing list
cfe-co