summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/typo-correction-delayed.cpp
diff options
context:
space:
mode:
authorKaelyn Takata <rikka@google.com>2014-11-21 18:48:00 +0000
committerKaelyn Takata <rikka@google.com>2014-11-21 18:48:00 +0000
commitb108f094f02cca962eb0bdfafc9fdd7f86ae3b93 (patch)
tree40939620100e0cd2aee49366a2ce225c3ccb0870 /test/SemaCXX/typo-correction-delayed.cpp
parent7f0ea0ae7a555c89a598434b1ad147dfcd4f1e3b (diff)
Properly correct initializer expressions based on whether they would be valid.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/typo-correction-delayed.cpp')
-rw-r--r--test/SemaCXX/typo-correction-delayed.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/SemaCXX/typo-correction-delayed.cpp b/test/SemaCXX/typo-correction-delayed.cpp
index c82f865a86..124f0ec2a1 100644
--- a/test/SemaCXX/typo-correction-delayed.cpp
+++ b/test/SemaCXX/typo-correction-delayed.cpp
@@ -59,3 +59,37 @@ void testExprFilter(Item *i) {
Item *j;
j = i->Next(); // expected-error {{no member named 'Next' in 'Item'; did you mean 'next'?}}
}
+
+// Test that initializer expressions are handled correctly and that the type
+// being initialized is taken into account when choosing a correction.
+namespace initializerCorrections {
+struct Node {
+ string text() const;
+ // Node* Next() is not implemented yet
+};
+void f(Node *node) {
+ // text is only an edit distance of 1 from Next, but would trigger type
+ // conversion errors if used in this initialization expression.
+ Node *next = node->Next(); // expected-error-re {{no member named 'Next' in 'initializerCorrections::Node'{{$}}}}
+}
+
+struct LinkedNode {
+ LinkedNode* next(); // expected-note {{'next' declared here}}
+ string text() const;
+};
+void f(LinkedNode *node) {
+ // text and next are equidistant from Next, but only one results in a valid
+ // initialization expression.
+ LinkedNode *next = node->Next(); // expected-error {{no member named 'Next' in 'initializerCorrections::LinkedNode'; did you mean 'next'?}}
+}
+
+struct NestedNode {
+ NestedNode* Nest();
+ NestedNode* next();
+ string text() const;
+};
+void f(NestedNode *node) {
+ // There are two equidistant, usable corrections for Next: next and Nest
+ NestedNode *next = node->Next(); // expected-error-re {{no member named 'Next' in 'initializerCorrections::NestedNode'{{$}}}}
+}
+}