[clang-tools-extra] r366446 - [clangd] Suppress unwritten scopes when expanding auto.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 08:13:45 PDT 2019
Author: hokein
Date: Thu Jul 18 08:13:45 2019
New Revision: 366446
URL: http://llvm.org/viewvc/llvm-project?rev=366446&view=rev
Log:
[clangd] Suppress unwritten scopes when expanding auto.
Summary: otherwise the replacement will break the code.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64627
Modified:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/clangd/AST.h
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
Modified: clang-tools-extra/trunk/clangd/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=366446&r1=366445&r2=366446&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/AST.cpp (original)
+++ clang-tools-extra/trunk/clangd/AST.cpp Thu Jul 18 08:13:45 2019
@@ -192,6 +192,7 @@ std::string shortenNamespace(const llvm:
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),
Modified: clang-tools-extra/trunk/clangd/AST.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.h?rev=366446&r1=366445&r2=366446&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/AST.h (original)
+++ clang-tools-extra/trunk/clangd/AST.h Thu Jul 18 08:13:45 2019
@@ -67,7 +67,8 @@ llvm::Optional<SymbolID> getSymbolID(con
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
Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp?rev=366446&r1=366445&r2=366446&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp Thu Jul 18 08:13:45 2019
@@ -663,6 +663,20 @@ TEST(TweakTest, ExpandAutoType) {
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
More information about the cfe-commits
mailing list