summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/spellcheck-typenames.c
blob: ae22ce318ae2641fafe472c3ad1963ddf1b1393b (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* { dg-do compile } */
/* { dg-options "-fdiagnostics-show-caret" } */

void test_1 (signed char e);

/* PR c/70339.  */
void test_2 (singed char e); /* { dg-error "14: unknown type name .singed.; did you mean .signed.?" } */
/* { dg-begin-multiline-output "" }
 void test_2 (singed char e);
              ^~~~~~
              signed
   { dg-end-multiline-output "" } */

void test_3 (car e); /* { dg-error "14: unknown type name .car.; did you mean .char.?" } */
/* { dg-begin-multiline-output "" }
 void test_3 (car e);
              ^~~
              char
   { dg-end-multiline-output "" } */

/* TODO: this one could be handled better.  */
void test_4 (signed car e); /* { dg-error "25: before .e." } */
/* { dg-begin-multiline-output "" }
 void test_4 (signed car e);
                         ^
   { dg-end-multiline-output "" } */

/* Verify that we handle misspelled typedef names.  */

typedef struct something {} something_t;

some_thing_t test_5; /* { dg-error "1: unknown type name .some_thing_t.; did you mean .something_t.?" } */
  /* { dg-begin-multiline-output "" }
 some_thing_t test_5;
 ^~~~~~~~~~~~
 something_t
   { dg-end-multiline-output "" } */

/* TODO: we don't yet handle misspelled struct names.  */
struct some_thing test_6; /* { dg-error "storage size of .test_6. isn't known" } */
  /* { dg-begin-multiline-output "" }
 struct some_thing test_6;
                   ^~~~~~
   { dg-end-multiline-output "" } */

typedef long int64_t;
int64 i; /* { dg-error "unknown type name 'int64'; did you mean 'int64_t'?" } */
/* { dg-begin-multiline-output "" }
 int64 i;
 ^~~~~
 int64_t
   { dg-end-multiline-output "" } */

/* Verify that gcc doesn't offer nonsensical suggestions.  */

nonsensical_suggestion_t var; /* { dg-bogus "did you mean" } */
/* { dg-error "unknown type name" "" { target { *-*-* } } 56 } */
/* { dg-begin-multiline-output "" }
 nonsensical_suggestion_t var;
 ^~~~~~~~~~~~~~~~~~~~~~~~
   { dg-end-multiline-output "" } */


/* In the following, we should suggest inserting "struct" (rather
   than "did you mean 'float'") and provide a fixit hint.  */
struct foo_t {
  int i;
};
foo_t *foo_ptr; /* { dg-error "1: unknown type name .foo_t.; use .struct. keyword to refer to the type" } */
/* { dg-begin-multiline-output "" }
 foo_t *foo_ptr;
 ^~~~~
 struct
   { dg-end-multiline-output "" } */


/* Similarly for unions.  */
union bar_t {
  int i;
  char j;
};
bar_t *bar_ptr; /* { dg-error "1: unknown type name .bar_t.; use .union. keyword to refer to the type" } */
/* { dg-begin-multiline-output "" }
 bar_t *bar_ptr;
 ^~~~~
 union
   { dg-end-multiline-output "" } */


/* Similarly for enums.  */
enum baz {
  BAZ_FIRST,
  BAZ_SECOND
};
baz value; /* { dg-error "1: unknown type name .baz.; use .enum. keyword to refer to the type" } */
/* { dg-begin-multiline-output "" }
 baz value;
 ^~~
 enum
   { dg-end-multiline-output "" } */

/* TODO: it would be better to detect the "singed" vs "signed" typo here.  */
singed char ch; /* { dg-error "8: before .char." } */
/* { dg-begin-multiline-output "" }
 singed char ch;
        ^~~~
   { dg-end-multiline-output "" } */