[PATCH] D64627: [clangd] Suppress unwritten scopes when expanding auto.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 03:38:51 PDT 2019


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

otherwise the replacement will break the code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64627

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -663,6 +663,20 @@
     const char * x = "test";
   )cpp";
   checkTransform(ID, Input, Output);
+
+  Input = R"cpp(
+  namespace {
+  class Foo {};
+  }
+  au^to f = Foo();
+  )cpp";
+  Output = R"cpp(
+  namespace {
+  class Foo {};
+  }
+  Foo f = Foo();
+  )cpp";
+  checkTransform(ID, Input, Output);
 }
 
 } // namespace
Index: clang-tools-extra/clangd/AST.h
===================================================================
--- clang-tools-extra/clangd/AST.h
+++ clang-tools-extra/clangd/AST.h
@@ -67,7 +67,8 @@
                                      const MacroInfo *MI,
                                      const SourceManager &SM);
 
-/// Returns a QualType as string.
+/// Returns a QualType as string. The result doesn't contain unwritten scopes
+/// like annoymous/inline namespace.
 std::string printType(const QualType QT, const DeclContext & Context);
 
 /// Try to shorten the OriginalName by removing namespaces from the left of
Index: clang-tools-extra/clangd/AST.cpp
===================================================================
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -192,6 +192,7 @@
 
 std::string printType(const QualType QT, const DeclContext & Context){
   PrintingPolicy PP(Context.getParentASTContext().getPrintingPolicy());
+  PP.SuppressUnwrittenScope = 1;
   PP.SuppressTagKeyword = 1;
   return shortenNamespace(
       QT.getAsString(PP),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64627.209454.patch
Type: text/x-patch
Size: 1652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190712/c0239c66/attachment.bin>


More information about the cfe-commits mailing list