Skip to content

Commit

Permalink
[clangd] Enable expand-auto for decltype(auto).
Browse files Browse the repository at this point in the history
  • Loading branch information
hokein committed Jan 10, 2022
1 parent 392aa97 commit 37ec65e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
Expand Up @@ -96,9 +96,7 @@ bool ExpandAutoType::prepare(const Selection& Inputs) {
if (auto *Node = Inputs.ASTSelection.commonAncestor()) {
if (auto *TypeNode = Node->ASTNode.get<TypeLoc>()) {
if (const AutoTypeLoc Result = TypeNode->getAs<AutoTypeLoc>()) {
// Code in apply() does handle 'decltype(auto)' yet.
if (!Result.getTypePtr()->isDecltypeAuto() &&
!isStructuredBindingType(Node) &&
if (!isStructuredBindingType(Node) &&
!isDeducedAsLambda(Node, Result.getBeginLoc()) &&
!isTemplateParam(Node))
CachedLocation = Result;
Expand Down
Expand Up @@ -71,7 +71,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
apply("void ns::Func() { au^to x = new ns::Class::Nested{}; }"),
"void ns::Func() { ns::Class::Nested * x = new ns::Class::Nested{}; }");

EXPECT_UNAVAILABLE("dec^ltype(au^to) x = 10;");
EXPECT_EQ(apply("dec^ltype(auto) x = 10;"), "int x = 10;");
EXPECT_EQ(apply("decltype(au^to) x = 10;"), "int x = 10;");
// expanding types in structured bindings is syntactically invalid.
EXPECT_UNAVAILABLE("const ^auto &[x,y] = (int[]){1,2};");

Expand Down

0 comments on commit 37ec65e

Please sign in to comment.