Skip to content

Commit

Permalink
add C23 error diagnostic: missing type specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsan901998 authored and Vexu committed Oct 5, 2023
1 parent 7bf3d05 commit 6bd76a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ const messages = struct {
const kind = .warning;
const all = true;
};
pub const missing_type_specifier_c2x = struct {
const msg = "a type specifier is required for all declarations";
const kind = .@"error";
};
pub const multiple_storage_class = struct {
const msg = "cannot combine with previous '{s}' declaration specifier";
const extra = .str;
Expand Down
6 changes: 5 additions & 1 deletion src/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,11 @@ pub const Builder = struct {
ty = typeof;
} else {
ty.specifier = .int;
try p.err(.missing_type_specifier);
if (p.comp.langopts.standard.atLeast(.c2x)) {
try p.err(.missing_type_specifier_c2x);
} else {
try p.err(.missing_type_specifier);
}
}
},
.void => ty.specifier = .void,
Expand Down
4 changes: 4 additions & 0 deletions test/cases/missing type specifier.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//aro-args
#define EXPECTED_ERRORS \
"missing type specifier.c:4:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]"
static x = 5;
4 changes: 4 additions & 0 deletions test/cases/missing type specifier_c2x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//aro-args -std=c2x
#define EXPECTED_ERRORS \
"missing type specifier_c2x.c:4:8: error: a type specifier is required for all declarations"
static x = 5;

0 comments on commit 6bd76a9

Please sign in to comment.