diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-11-07 10:02:31 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-11-07 10:02:31 +0000 |
commit | ebf0a6d75dcb5715d5bf7097e749a4249d01e956 (patch) | |
tree | 8de53754d6278f1ffac8aced98e3ba6546677362 /clang/lib/Sema/SemaCodeComplete.cpp | |
parent | ed4bb266c8531a28399b2fab8161ff67e4eaa650 (diff) | |
download | bcm5719-llvm-ebf0a6d75dcb5715d5bf7097e749a4249d01e956.tar.gz bcm5719-llvm-ebf0a6d75dcb5715d5bf7097e749a4249d01e956.zip |
[CodeComplete] Do not complete self-initializations
Summary:
Removes references to initialized variable from the following completions:
int x = ^;
Handles only the trivial cases where the variable name is completed
immediately at the start of initializer or assignment, more complicated
cases aren't covered, e.g. these completions still contain 'x':
// More complicated expressions.
int x = foo(^);
int x = 10 + ^;
// Other kinds of initialization.
int x{^};
int x(^);
// Constructor initializers.
struct Foo {
Foo() : x(^) {}
int x;
};
We should address those in the future, but they are outside of the scope of
this initial change.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D54156
llvm-svn: 346301
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 6c4c7e622d4..95714852c16 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -4747,7 +4747,12 @@ void Sema::CodeCompleteInitializer(Scope *S, Decl *D) { return; } - CodeCompleteExpression(S, VD->getType()); + CodeCompleteExpressionData Data; + Data.PreferredType = VD->getType(); + // Ignore VD to avoid completing the variable itself, e.g. in 'int foo = ^'. + Data.IgnoreDecls.push_back(VD); + + CodeCompleteExpression(S, Data); } void Sema::CodeCompleteReturn(Scope *S) { |