aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/spellcheck-fields.C
blob: 504992aa541e38ec458773c6ba582a5eb3f21540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* { dg-do compile } */

struct foo
{
  int foo;
  int bar;
  int baz;
};

int test (struct foo *ptr)
{
  return ptr->m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */
}

int test2 (void)
{
  struct foo instance = {0, 0, 0};
  return instance.m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */
}

struct s {
    struct j { int aa; } kk;
    int ab;
};

void test3 (struct s x)
{
  x.ac;  /* { dg-error "'struct s' has no member named 'ac'; did you mean 'ab'?" } */
}

int test4 (struct foo *ptr)
{
  return sizeof (ptr->foa); /* { dg-error "'struct foo' has no member named 'foa'; did you mean 'foo'?" } */
}

/* Verify that we don't offer nonsensical suggestions.  */

int test5 (struct foo *ptr)
{
  return ptr->this_is_unlike_any_of_the_fields;   /* { dg-bogus "did you mean" } */
  /* { dg-error "has no member named" "" { target *-*-* } .-1 } */
}

union u
{
  int color;
  int shape;
};

int test6 (union u *ptr)
{
  return ptr->colour; /* { dg-error "'union u' has no member named 'colour'; did you mean 'color'?" } */
}

struct has_anon
{
  struct { int color; } s;
};

int test7 (struct has_anon *ptr)
{
  return ptr->s.colour; /* { dg-error "'struct has_anon::<unnamed>' has no member named 'colour'; did you mean 'color'?" } */
}

int test8 (foo &ref)
{
  return ref.m_bar; /* { dg-error "'struct foo' has no member named 'm_bar'; did you mean 'bar'?" } */
}

struct bar : public foo
{
  int fizz;
  typedef int my_type;
};

int test9 (bar *ptr)
{
  return ptr->fuzz; /* { dg-error "'struct bar' has no member named 'fuzz'; did you mean 'fizz'?" } */
}

int test10 (bar *ptr)
{
  return ptr->m_foo; /* { dg-error "'struct bar' has no member named 'm_foo'; did you mean 'foo'?" } */
}

int test11 (bar *ptr)
{
  return ptr->mytype; /* { dg-error "'struct bar' has no member named 'mytype'; did you mean 'my_type'?" } */
}