C++: simplify output from suggest_alternatives_for
[official-gcc.git] / gcc / testsuite / g++.dg / spellcheck-single-vs-multiple.C
blob7d9b87a1d307289e1129830e872d230910787090
1 /* Example of namespace suggestions, covering the special-case handling
2    of where there's one suggestion, vs multiple suggestions.  */
4 /* { dg-options "-fdiagnostics-show-caret" } */
6 /* Missing a namespace, where there's one candidate.
7    Verify that we issue a fix-it hint.  */
9 namespace ns1
11   void foo_1 (); // { dg-line foo_1_decl }
14 void test_1 ()
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 "" } */
29 /* Missing a namespace, where there are multiple candidates.
30    We don't issue a fix-it hint.  */
32 namespace ns2_a
34   char foo_2 (); // { dg-line ns2_a_foo_2_decl }
37 namespace ns2_b
39   int foo_2 (); // { dg-line ns2_b_foo_2_decl }
42 void test_2 ()
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 "" } */
63 /* Misspelling within an explicit namespace.
64    Verify that we issue a fix-it hint.  */
66 namespace ns3
68   void foo_3 ();
71 void test_3 ()
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 "" } */