1 /* Suggestions involving namespaces.
2
3 The long variable names in this test case are close enough that we offer
4 spellchecking suggestions for them in the given namespace, with fix-it
5 hints.
6
7 The short variable names don't get spellchecking suggestions; instead
8 we offer suggestions about other namespaces. However, as we don't
9 reliably have location information about the namespace part of the name,
10 we shouldn't offer fix-it hints for such cases. */
11
12 // { dg-do compile }
13 // { dg-options "-fdiagnostics-show-caret" }
14
15 namespace outer_ns {
16 int var_in_outer_ns; // { dg-line decl_of_var_in_outer_ns }
17 int o; // { dg-line decl_of_o }
18
19 namespace inner_ns_a {
20 int var_in_inner_ns_a;
21 int a; // { dg-line decl_of_a }
22 }
23 namespace inner_ns_b {
24 int var_in_inner_ns_b;
25 int b; // { dg-line decl_of_b }
26 }
27 }
28
29 /* This one should get spell-corrected within the same namespace,
30 with a fix-it hint. */
31
test_1_long(void)32 int test_1_long (void) {
33 return outer_ns::var_in_inner_ns_a; // { dg-error "did you mean 'var_in_outer_ns'" }
34 /* { dg-begin-multiline-output "" }
35 return outer_ns::var_in_inner_ns_a;
36 ^~~~~~~~~~~~~~~~~
37 var_in_outer_ns
38 { dg-end-multiline-output "" } */
39 }
40
41 /* This one should get a namespace suggestion (child namespace),
42 with no fix-it hint. */
43
test_1_short(void)44 int test_1_short (void) {
45 return outer_ns::a; // { dg-error "did you mean 'outer_ns::inner_ns_a::a'" }
46 /* { dg-begin-multiline-output "" }
47 return outer_ns::a;
48 ^
49 { dg-end-multiline-output "" } */
50 // { dg-message "declared here" "" { target *-*-*} decl_of_a }
51 /* { dg-begin-multiline-output "" }
52 int a;
53 ^
54 { dg-end-multiline-output "" } */
55 }
56
57 /* This one should get spell-corrected within the same namespace,
58 with a fix-it hint. */
59
test_2_long(void)60 int test_2_long (void) {
61 return outer_ns::inner_ns_a::var_in_outer_ns; // { dg-error "did you mean 'var_in_inner_ns_a'" }
62 /* { dg-begin-multiline-output "" }
63 return outer_ns::inner_ns_a::var_in_outer_ns;
64 ^~~~~~~~~~~~~~~
65 var_in_inner_ns_a
66 { dg-end-multiline-output "" } */
67 }
68
69 /* This one should get a namespace suggestion (parent namespace),
70 with no fix-it hint. */
71
test_2_short(void)72 int test_2_short (void) {
73 return outer_ns::inner_ns_a::o; // { dg-error "did you mean 'outer_ns::o'" }
74 /* { dg-begin-multiline-output "" }
75 return outer_ns::inner_ns_a::o;
76 ^
77 { dg-end-multiline-output "" } */
78 // { dg-message "declared here" "" { target *-*-*} decl_of_o }
79 /* { dg-begin-multiline-output "" }
80 int o;
81 ^
82 { dg-end-multiline-output "" } */
83 }
84
85 /* This one should get spell-corrected within the same namespace,
86 with a fix-it hint. */
87
test_3_long(void)88 int test_3_long (void) {
89 return outer_ns::inner_ns_a::var_in_inner_ns_b; // { dg-error "did you mean 'var_in_inner_ns_a'" }
90 /* { dg-begin-multiline-output "" }
91 return outer_ns::inner_ns_a::var_in_inner_ns_b;
92 ^~~~~~~~~~~~~~~~~
93 var_in_inner_ns_a
94 { dg-end-multiline-output "" } */
95 }
96
97 /* This one should get a namespace suggestion (sibling namespace),
98 with no fix-it hint. */
99
test_3_short(void)100 int test_3_short (void) {
101 return outer_ns::inner_ns_a::b; // { dg-error "did you mean 'outer_ns::inner_ns_b::b'" }
102 /* { dg-begin-multiline-output "" }
103 return outer_ns::inner_ns_a::b;
104 ^
105 { dg-end-multiline-output "" } */
106 // { dg-message "declared here" "" { target *-*-*} decl_of_b }
107 /* { dg-begin-multiline-output "" }
108 int b;
109 ^
110 { dg-end-multiline-output "" } */
111 }
112
113 /* This one should get a namespace suggestion, from the global ns to a child ns.
114 It should get a fix-it hint. */
115
test_4_long(void)116 int test_4_long (void) {
117 return ::var_in_outer_ns; // { dg-error "did you mean 'outer_ns::var_in_outer_ns'" }
118 /* { dg-begin-multiline-output "" }
119 return ::var_in_outer_ns;
120 ^~~~~~~~~~~~~~~
121 outer_ns::var_in_outer_ns
122 { dg-end-multiline-output "" } */
123 // { dg-message "declared here" "" { target *-*-*} decl_of_var_in_outer_ns }
124 /* { dg-begin-multiline-output "" }
125 int var_in_outer_ns;
126 ^~~~~~~~~~~~~~~
127 { dg-end-multiline-output "" } */
128 }
129