File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -53,13 +53,24 @@ REGISTER_TWEAK(ExpandAutoType)
53
53
54
54
std::string ExpandAutoType::title () const { return " Expand auto type" ; }
55
55
56
+ // Structured bindings must use auto, e.g. `const auto& [a,b,c] = ...;`.
57
+ // Return whether N (an AutoTypeLoc) is such an auto that must not be expanded.
58
+ bool isStructuredBindingType (const SelectionTree::Node *N) {
59
+ // Walk up the TypeLoc chain, because auto may be qualified.
60
+ while (N && N->ASTNode .get <TypeLoc>())
61
+ N = N->Parent ;
62
+ // The relevant type is the only direct type child of a Decomposition.
63
+ return N && N->ASTNode .get <DecompositionDecl>();
64
+ }
65
+
56
66
bool ExpandAutoType::prepare (const Selection& Inputs) {
57
67
CachedLocation = llvm::None;
58
68
if (auto *Node = Inputs.ASTSelection .commonAncestor ()) {
59
69
if (auto *TypeNode = Node->ASTNode .get <TypeLoc>()) {
60
70
if (const AutoTypeLoc Result = TypeNode->getAs <AutoTypeLoc>()) {
61
71
// Code in apply() does handle 'decltype(auto)' yet.
62
- if (!Result.getTypePtr ()->isDecltypeAuto ())
72
+ if (!Result.getTypePtr ()->isDecltypeAuto () &&
73
+ !isStructuredBindingType (Node))
63
74
CachedLocation = Result;
64
75
}
65
76
}
Original file line number Diff line number Diff line change @@ -572,6 +572,8 @@ TEST_F(ExpandAutoTypeTest, Test) {
572
572
R"cpp( const char * x = "test";)cpp" );
573
573
574
574
EXPECT_UNAVAILABLE (" dec^ltype(au^to) x = 10;" );
575
+ // expanding types in structured bindings is syntactically invalid.
576
+ EXPECT_UNAVAILABLE (" const ^auto &[x,y] = (int[]){1,2};" );
575
577
576
578
// FIXME: Auto-completion in a template requires disabling delayed template
577
579
// parsing.
You can’t perform that action at this time.
0 commit comments