1 /* Example of namespace suggestions, covering the special-case handling
2    of where there's one suggestion, vs multiple suggestions.  */
3 
4 /* { dg-options "-fdiagnostics-show-caret" } */
5 
6 /* Missing a namespace, where there's one candidate.
7    Verify that we issue a fix-it hint.  */
8 
9 namespace ns1
10 {
11   void foo_1 (); // { dg-line foo_1_decl }
12 }
13 
test_1()14 void test_1 ()
15 {
16   foo_1 (); // { dg-error "'foo_1' was not declared in this scope; did you mean 'ns1::foo_1'\\?" }
17   /* { dg-begin-multiline-output "" }
18    foo_1 ();
19    ^~~~~
20    ns1::foo_1
21      { dg-end-multiline-output "" } */
22   // { dg-message "'ns1::foo_1' declared here" "" { target *-*-*} foo_1_decl }
23   /* { dg-begin-multiline-output "" }
24    void foo_1 ();
25         ^~~~~
26      { dg-end-multiline-output "" } */
27 }
28 
29 /* Missing a namespace, where there are multiple candidates.
30    We don't issue a fix-it hint.  */
31 
32 namespace ns2_a
33 {
34   char foo_2 (); // { dg-line ns2_a_foo_2_decl }
35 }
36 
37 namespace ns2_b
38 {
39   int foo_2 (); // { dg-line ns2_b_foo_2_decl }
40 }
41 
test_2()42 void test_2 ()
43 {
44   foo_2 (); // { dg-line foo_2_usage }
45   // { dg-error "'foo_2' was not declared in this scope" "" { target *-*-*} foo_2_usage }
46   /* { dg-begin-multiline-output "" }
47    foo_2 ();
48    ^~~~~
49      { dg-end-multiline-output "" } */
50   // { dg-message "suggested alternatives:" "" { target *-*-*} foo_2_usage }
51   // { dg-message "  'ns2_a::foo_2'" "" { target *-*-*} ns2_a_foo_2_decl }
52   /* { dg-begin-multiline-output "" }
53    char foo_2 ();
54         ^~~~~
55      { dg-end-multiline-output "" } */
56   // { dg-message "  'ns2_b::foo_2'" "" { target *-*-*} ns2_b_foo_2_decl }
57   /* { dg-begin-multiline-output "" }
58    int foo_2 ();
59        ^~~~~
60      { dg-end-multiline-output "" } */
61 }
62 
63 /* Misspelling within an explicit namespace.
64    Verify that we issue a fix-it hint.  */
65 
66 namespace ns3
67 {
68   void foo_3 ();
69 }
70 
test_3()71 void test_3 ()
72 {
73   ns3::goo_3 (); // { dg-error "'goo_3' is not a member of 'ns3'; did you mean 'foo_3'\\?" }
74   /* { dg-begin-multiline-output "" }
75    ns3::goo_3 ();
76         ^~~~~
77         foo_3
78      { dg-end-multiline-output "" } */
79 }
80