| 1 |
/* { dg-do compile } */ |
| 2 |
|
| 3 |
struct foo |
| 4 |
{ |
| 5 |
int foo; |
| 6 |
int bar; |
| 7 |
int baz; |
| 8 |
}; |
| 9 |
|
| 10 |
int test (struct foo *ptr) |
| 11 |
{ |
| 12 |
return ptr->m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */ |
| 13 |
} |
| 14 |
|
| 15 |
int test2 (void) |
| 16 |
{ |
| 17 |
struct foo instance = {0, 0, 0}; |
| 18 |
return instance.m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */ |
| 19 |
} |
| 20 |
|
| 21 |
struct s { |
| 22 |
struct j { int aa; } kk; |
| 23 |
int ab; |
| 24 |
}; |
| 25 |
|
| 26 |
void test3 (struct s x) |
| 27 |
{ |
| 28 |
x.ac; /* { dg-error "'struct s' has no member named 'ac'; did you mean 'ab'?" } */ |
| 29 |
} |
| 30 |
|
| 31 |
int test4 (struct foo *ptr) |
| 32 |
{ |
| 33 |
return sizeof (ptr->foa); /* { dg-error "'struct foo' has no member named 'foa'; did you mean 'foo'?" } */ |
| 34 |
} |
| 35 |
|
| 36 |
/* Verify that we don't offer nonsensical suggestions. */ |
| 37 |
|
| 38 |
int test5 (struct foo *ptr) |
| 39 |
{ |
| 40 |
return ptr->this_is_unlike_any_of_the_fields; /* { dg-bogus "did you mean" } */ |
| 41 |
/* { dg-error "has no member named" "" { target *-*-* } .-1 } */ |
| 42 |
} |
| 43 |
|
| 44 |
union u |
| 45 |
{ |
| 46 |
int color; |
| 47 |
int shape; |
| 48 |
}; |
| 49 |
|
| 50 |
int test6 (union u *ptr) |
| 51 |
{ |
| 52 |
return ptr->colour; /* { dg-error "'union u' has no member named 'colour'; did you mean 'color'?" } */ |
| 53 |
} |
| 54 |
|
| 55 |
struct has_anon |
| 56 |
{ |
| 57 |
struct { int color; } s; |
| 58 |
}; |
| 59 |
|
| 60 |
int test7 (struct has_anon *ptr) |
| 61 |
{ |
| 62 |
return ptr->s.colour; /* { dg-error "'struct has_anon::<unnamed>' has no member named 'colour'; did you mean 'color'?" } */ |
| 63 |
} |
| 64 |
|
| 65 |
int test8 (foo &ref) |
| 66 |
{ |
| 67 |
return ref.m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */ |
| 68 |
} |
| 69 |
|
| 70 |
struct bar : public foo |
| 71 |
{ |
| 72 |
int fizz; |
| 73 |
typedef int my_type; |
| 74 |
}; |
| 75 |
|
| 76 |
int test9 (bar *ptr) |
| 77 |
{ |
| 78 |
return ptr->fuzz; /* { dg-error "'struct bar' has no member named 'fuzz'; did you mean 'fizz'?" } */ |
| 79 |
} |
| 80 |
|
| 81 |
int test10 (bar *ptr) |
| 82 |
{ |
| 83 |
return ptr->m_foo; /* { dg-error "'struct bar' has no member named 'm_foo'; did you mean 'foo'?" } */ |
| 84 |
} |
| 85 |
|
| 86 |
int test11 (bar *ptr) |
| 87 |
{ |
| 88 |
return ptr->mytype; /* { dg-error "'struct bar' has no member named 'mytype'; did you mean 'my_type'?" } */ |
| 89 |
} |