Commit f5e2f19
committed
[clang] Emit unified error for 'auto' combined with type specifiers
This change improves the diagnostic when 'auto' is combined with a type
specifier by emitting a unified error message "'auto' cannot be combined
with a type specifier" instead of the generic "cannot combine with previous
'auto' declaration specifier" error.
The parser now checks for:
1. Builtin types (int, void, char, etc.) after 'auto' using lookahead
2. Identifier types (typedefs, template parameters, etc.) using semantic
lookup via Actions.getTypeName()
To avoid false positives, the check is limited to:
- Simple declaration contexts (DSC_normal, DSC_top_level, DSC_class)
- Simple variable declarations: 'auto Type variable_name' pattern
- Skips complex declarators (function pointers, member pointers, qualified
names, etc.)
- Skips ambiguous cases like 'auto Type = value' where Type could be a
variable name
For builtin types, the parser emits the error and exits early. For
identifier types, it uses semantic lookup to determine if the identifier
is a known type before emitting the error.
Test updates:
- Updated cwg3xx.cpp to account for C++98 vs C++11 behavior differences
- Updated p2.cpp to include expected warning for empty parentheses in
block scope
Fixes incorrect diagnostics for cases like:
auto int x; // Now correctly diagnosed
auto Ty x; // Now correctly diagnosed (Ty is a type)
auto S<T>::f(); // Correctly skipped (out-of-line definition)
auto Class::* // Correctly skipped (member pointer)
Signed-off-by: Osama Abdelkader <[email protected]>1 parent 88511de commit f5e2f19
File tree
4 files changed
+89
-12
lines changed- clang
- lib/Parse
- test
- CXX
- dcl.dcl/dcl.spec/dcl.stc
- drs
- Parser
4 files changed
+89
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4092 | 4092 | | |
4093 | 4093 | | |
4094 | 4094 | | |
4095 | | - | |
4096 | | - | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
4097 | 4098 | | |
4098 | 4099 | | |
4099 | | - | |
4100 | | - | |
4101 | | - | |
4102 | | - | |
4103 | | - | |
| 4100 | + | |
4104 | 4101 | | |
4105 | 4102 | | |
4106 | 4103 | | |
4107 | 4104 | | |
4108 | 4105 | | |
| 4106 | + | |
4109 | 4107 | | |
4110 | 4108 | | |
4111 | 4109 | | |
4112 | 4110 | | |
| 4111 | + | |
4113 | 4112 | | |
4114 | 4113 | | |
4115 | 4114 | | |
| |||
4121 | 4120 | | |
4122 | 4121 | | |
4123 | 4122 | | |
| 4123 | + | |
4124 | 4124 | | |
4125 | 4125 | | |
4126 | | - | |
4127 | | - | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
| 4133 | + | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
| 4162 | + | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + | |
| 4166 | + | |
| 4167 | + | |
| 4168 | + | |
| 4169 | + | |
| 4170 | + | |
| 4171 | + | |
| 4172 | + | |
| 4173 | + | |
| 4174 | + | |
| 4175 | + | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
| 4184 | + | |
| 4185 | + | |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
| 4193 | + | |
| 4194 | + | |
4128 | 4195 | | |
4129 | 4196 | | |
4130 | 4197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1739 | 1739 | | |
1740 | 1740 | | |
1741 | 1741 | | |
1742 | | - | |
1743 | | - | |
| 1742 | + | |
| 1743 | + | |
1744 | 1744 | | |
1745 | 1745 | | |
1746 | 1746 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments