1 // { dg-do compile { target c++11 } }
2 // { dg-options "-fdiagnostics-show-caret" }
3
4 /* Verify that we offer suggestions for misspelled values
5 in scoped enums, and for values from scoped enums that
6 are missing their scope.
7 Verify that we emit fix-it hints for those cases for
8 which we have adequate location information. */
9
10 enum class vegetable { CARROT, TURNIP }; // { dg-line decl_of_vegetable }
11 namespace pasta
12 {
13 enum class shape { LASAGNA, LINGUINE, SPAGHETTI, TAGLIATELLE }; // { dg-line decl_of_shape }
14 }
15
misspelled_value_in_scoped_enum()16 void misspelled_value_in_scoped_enum ()
17 {
18 vegetable::TURNUP; // { dg-error "'TURNUP' is not a member of 'vegetable'; did you mean 'TURNIP'" }
19 /* { dg-begin-multiline-output "" }
20 vegetable::TURNUP;
21 ^~~~~~
22 TURNIP
23 { dg-end-multiline-output "" } */
24 }
25
misspelled_value_using_explicit_ns()26 void misspelled_value_using_explicit_ns ()
27 {
28 pasta::shape::SPOOGHETTI; // { dg-error "'SPOOGHETTI' is not a member of 'pasta::shape'; did you mean 'SPAGHETTI'" }
29 /* { dg-begin-multiline-output "" }
30 pasta::shape::SPOOGHETTI;
31 ^~~~~~~~~~
32 SPAGHETTI
33 { dg-end-multiline-output "" } */
34 }
35
36 namespace pasta {
misspelled_value_using_implicit_ns()37 void misspelled_value_using_implicit_ns ()
38 {
39 shape::SPOOGHETTI; // { dg-error "'SPOOGHETTI' is not a member of 'pasta::shape'; did you mean 'SPAGHETTI'" }
40 /* { dg-begin-multiline-output "" }
41 shape::SPOOGHETTI;
42 ^~~~~~~~~~
43 SPAGHETTI
44 { dg-end-multiline-output "" } */
45 }
46 } // namespace pasta
47
unqualified_enum_in_global_ns()48 void unqualified_enum_in_global_ns ()
49 {
50 CARROT; // { dg-error "'CARROT' was not declared in this scope; did you mean 'vegetable::CARROT'" }
51 /* { dg-begin-multiline-output "" }
52 CARROT;
53 ^~~~~~
54 vegetable::CARROT
55 { dg-end-multiline-output "" } */
56 // { dg-message "'vegetable::CARROT' declared here" "" { target *-*-* } decl_of_vegetable }
57 /* { dg-begin-multiline-output "" }
58 enum class vegetable { CARROT, TURNIP };
59 ^~~~~~
60 { dg-end-multiline-output "" } */
61 }
62
unqualified_enum_in_ns()63 void unqualified_enum_in_ns ()
64 {
65 LASAGNA; // { dg-error "'LASAGNA' was not declared in this scope; did you mean 'pasta::shape::LASAGNA'" }
66 /* { dg-begin-multiline-output "" }
67 LASAGNA;
68 ^~~~~~~
69 pasta::shape::LASAGNA
70 { dg-end-multiline-output "" } */
71 // { dg-message "'pasta::shape::LASAGNA' declared here" "" { target *-*-* } decl_of_shape }
72 /* { dg-begin-multiline-output "" }
73 enum class shape { LASAGNA, LINGUINE, SPAGHETTI, TAGLIATELLE };
74 ^~~~~~~
75 { dg-end-multiline-output "" } */
76 }
77
78 /* We can't guarantee location information here, so don't expect a
79 fix-it hint. */
80
unqualified_enum_in_explicit_ns()81 void unqualified_enum_in_explicit_ns ()
82 {
83 pasta::LINGUINE; // { dg-error "'LINGUINE' is not a member of 'pasta'; did you mean 'pasta::shape::LINGUINE'" }
84 /* { dg-begin-multiline-output "" }
85 pasta::LINGUINE;
86 ^~~~~~~~
87 { dg-end-multiline-output "" } */
88 // { dg-message "'pasta::shape::LINGUINE' declared here" "" { target *-*-* } decl_of_shape }
89 /* { dg-begin-multiline-output "" }
90 enum class shape { LASAGNA, LINGUINE, SPAGHETTI, TAGLIATELLE };
91 ^~~~~~~~
92 { dg-end-multiline-output "" } */
93 }
94
95 namespace pasta {
unqualified_enum_in_implicit_ns()96 void unqualified_enum_in_implicit_ns ()
97 {
98 TAGLIATELLE; // { dg-error "'TAGLIATELLE' was not declared in this scope; did you mean 'pasta::shape::TAGLIATELLE'" }
99 /* { dg-begin-multiline-output "" }
100 TAGLIATELLE;
101 ^~~~~~~~~~~
102 pasta::shape::TAGLIATELLE
103 { dg-end-multiline-output "" } */
104 // { dg-message "'pasta::shape::TAGLIATELLE' declared here" "" { target *-*-* } decl_of_shape }
105 /* { dg-begin-multiline-output "" }
106 enum class shape { LASAGNA, LINGUINE, SPAGHETTI, TAGLIATELLE };
107 ^~~~~~~~~~~
108 { dg-end-multiline-output "" } */
109 }
110 }
111