summaryrefslogtreecommitdiffstats
path: root/test/CodeCompletion
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2016-11-03 07:36:17 +0000
committerOlivier Goffart <ogoffart@woboq.com>2016-11-03 07:36:17 +0000
commit7eeb47943ec7fa6ab7f9fc9847572137e7fc1f59 (patch)
treea88c1484c5af406afc7f2ac9a1d6c1ad4d465cfd /test/CodeCompletion
parent516761b09f4c93f8d5498f23f2c4583cb8d857bb (diff)
Fix heuristics skipping invalid ctor-initializers with C++11
Use better heuristics to detect if a '{' might be the start of the constructor body or not. Especially when there is a completion token. Fix the test 'test/CodeCompletion/ctor-initializer.cpp ' when clang defaults to c++11 The problem was is how we recover invalid code in the ctor-init part as we skip the function body. In particular, we want to know if a '{' is the begining of the body. In C++03, we always consider it as the beginng of the body. The problem was that in C++11, it may be the start of an initializer, so we skip over it, causing further parse errors later. (It is important that we are able to parse correctly the rest of the class definition, to know what are the class member, for example) This commit is improving the heuristics to decide if the '{' is starting a function body. The rules are the following: If we are not in a template argument, and that the previous tokens are not an identifier, or a >, then it is much more likely to be the function body. We verify that further by checking the token after the matching '}' The commit also fix the behavior when there is a code_completion token in the ctor-initializers. Differential Revision: https://reviews.llvm.org/D21502 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeCompletion')
-rw-r--r--test/CodeCompletion/ctor-initializer.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/test/CodeCompletion/ctor-initializer.cpp b/test/CodeCompletion/ctor-initializer.cpp
index 00af64dd4f..e54b347f9f 100644
--- a/test/CodeCompletion/ctor-initializer.cpp
+++ b/test/CodeCompletion/ctor-initializer.cpp
@@ -1,11 +1,13 @@
struct Base1 {
Base1() : {}
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:2:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: COMPLETION: Pattern : member1(<#args#>)
// CHECK-CC1: COMPLETION: Pattern : member2(<#args#>
Base1(int) : member1(123), {}
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:7:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:8:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:8:30 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2-NOT: COMPLETION: Pattern : member1(<#args#>)
// CHECK-CC2: COMPLETION: Pattern : member2(<#args#>
@@ -21,14 +23,16 @@ struct Derived : public Base1 {
};
Derived::Derived() : {}
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:25:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:25:22 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
// CHECK-CC3: COMPLETION: Pattern : Base1(<#args#>)
// CHECK-CC3: COMPLETION: Pattern : deriv1(<#args#>)
Derived::Derived(int) try : {
} catch (...) {
}
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:28:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:31:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:31:29 %s -o - | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4: COMPLETION: Pattern : Base1(<#args#>)
// CHECK-CC4: COMPLETION: Pattern : deriv1(<#args#>)
@@ -36,6 +40,23 @@ Derived::Derived(float) try : Base1(),
{
} catch (...) {
}
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:35:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:39:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:39:39 %s -o - | FileCheck -check-prefix=CHECK-CC5 %s
// CHECK-CC5-NOT: COMPLETION: Pattern : Base1(<#args#>)
// CHECK-CC5: COMPLETION: Pattern : deriv1(<#args#>)
+
+struct A {
+ A() : , member2() {}
+ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:49:9 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:49:9 %s -o - | FileCheck -check-prefix=CHECK-CC6 %s
+ // CHECK-CC6: COMPLETION: Pattern : member1(<#args#>
+ int member1, member2;
+};
+
+struct B {
+ B() : member2() {}
+ // RUN: %clang_cc1 -fsyntax-only -std=c++98 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+ // RUN: %clang_cc1 -fsyntax-only -std=c++14 -code-completion-at=%s:57:9 %s -o - | FileCheck -check-prefix=CHECK-CC7 %s
+ // CHECK-CC7: COMPLETION: Pattern : member1(<#args#>
+ int member1, member2;
+};