From 1c67a96b2b8aee8b1624cd32fad74e0ccff473df Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Wed, 19 Sep 2018 14:59:35 +0200 Subject: [backported/clang-8][CodeComplete] Generate completion fix-its for C code as well -------------------------------------------------------------------------- * https://reviews.llvm.org/D52261 -------------------------------------------------------------------------- Current completion fix-its approach does not provide OtherOpBase for C code. But we can easily proceed in this case taking the original Base type. Task-number: QTCREATORBUG-21104 Change-Id: I11d8bc417480a50291a07267ece9ff3a071961f0 Reviewed-by: Nikolai Kosjar --- lib/Parse/ParseExpr.cpp | 2 ++ test/CodeCompletion/member-access.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index cb28fcf9bd..be858a7023 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1728,6 +1728,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { Expr *Base = LHS.get(); Expr *CorrectedBase = CorrectedLHS.get(); + if (!CorrectedBase && !getLangOpts().CPlusPlus) + CorrectedBase = Base; // Code completion for a member access expression. Actions.CodeCompleteMemberReferenceExpr( diff --git a/test/CodeCompletion/member-access.c b/test/CodeCompletion/member-access.c index 226e182ab1..72afbf2ff9 100644 --- a/test/CodeCompletion/member-access.c +++ b/test/CodeCompletion/member-access.c @@ -10,3 +10,22 @@ void test(struct Point *p) { // CHECK-CC1: x // CHECK-CC1: y // CHECK-CC1: z +} + +struct Point2 { + float x; +}; + +void test2(struct Point2 p) { + p-> +} + +void test3(struct Point2 *p) { + p. +} + +// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s +// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".") + +// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s +// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->") -- cgit v1.2.3