Skip to content

Commit f187957

Browse files
committed
lint: accept _Complex type specifiers in any order
C23 6.7.3.1p2 says so. Seen in external/gpl3/gcc/dist/libquadmath/quadmath.h:33.
1 parent 13a7bbb commit f187957

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

tests/usr.bin/xlint/lint1/msg_308.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: msg_308.c,v 1.9 2025/04/12 15:49:50 rillig Exp $ */
1+
/* $NetBSD: msg_308.c,v 1.10 2026/01/20 23:33:05 rillig Exp $ */
22
# 3 "msg_308.c"
33

44
// Test for message: invalid type for _Complex [308]
@@ -15,3 +15,30 @@ _Complex plain_complex;
1515
/* expect+2: error: invalid type for _Complex [308] */
1616
/* expect+1: error: invalid type combination [4] */
1717
int _Complex int_complex;
18+
19+
void *ptr;
20+
21+
void
22+
reveal_types(void)
23+
{
24+
/* expect+1: ... 'float _Complex' [171] */
25+
ptr = (_Complex float)0.0;
26+
/* expect+1: ... 'float _Complex' [171] */
27+
ptr = (float _Complex)0.0;
28+
/* expect+1: ... 'double _Complex' [171] */
29+
ptr = (_Complex double)0.0;
30+
/* expect+1: ... 'double _Complex' [171] */
31+
ptr = (double _Complex)0.0;
32+
/* expect+1: ... 'long double _Complex' [171] */
33+
ptr = (_Complex double long)0.0;
34+
/* expect+1: ... 'long double _Complex' [171] */
35+
ptr = (_Complex long double)0.0;
36+
/* expect+1: ... 'long double _Complex' [171] */
37+
ptr = (double _Complex long)0.0;
38+
/* expect+1: ... 'long double _Complex' [171] */
39+
ptr = (double long _Complex)0.0;
40+
/* expect+1: ... 'long double _Complex' [171] */
41+
ptr = (long _Complex double)0.0;
42+
/* expect+1: ... 'long double _Complex' [171] */
43+
ptr = (long double _Complex)0.0;
44+
}

usr.bin/xlint/lint1/decl.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: decl.c,v 1.423 2026/01/17 14:27:08 rillig Exp $ */
1+
/* $NetBSD: decl.c,v 1.424 2026/01/20 23:33:05 rillig Exp $ */
22

33
/*
44
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
3838

3939
#include <sys/cdefs.h>
4040
#if defined(__RCSID)
41-
__RCSID("$NetBSD: decl.c,v 1.423 2026/01/17 14:27:08 rillig Exp $");
41+
__RCSID("$NetBSD: decl.c,v 1.424 2026/01/20 23:33:05 rillig Exp $");
4242
#endif
4343

4444
#include <sys/param.h>
@@ -352,11 +352,8 @@ dcs_add_type(type_t *tp)
352352
t = FCOMPLEX;
353353
else if (dcs->d_complex_mod == DOUBLE)
354354
t = DCOMPLEX;
355-
else {
356-
/* invalid type for _Complex */
357-
error(308);
358-
t = DCOMPLEX; /* just as a fallback */
359-
}
355+
else if (dcs->d_abstract_type == NO_TSPEC)
356+
t = COMPLEX;
360357
dcs->d_complex_mod = NO_TSPEC;
361358
}
362359

@@ -395,9 +392,11 @@ dcs_add_type(type_t *tp)
395392
dcs->d_invalid_type_combination = true;
396393
dcs->d_abstract_type = t;
397394
}
398-
} else if (t == PTR) {
395+
} else if (t == PTR)
399396
dcs->d_type = tp;
400-
} else {
397+
else if (t == COMPLEX && dcs->d_abstract_type == NO_TSPEC)
398+
dcs->d_abstract_type = t;
399+
else {
401400
if (dcs->d_abstract_type != NO_TSPEC)
402401
dcs->d_invalid_type_combination = true;
403402
dcs->d_abstract_type = t;
@@ -723,6 +722,17 @@ dcs_merge_declaration_specifiers(void)
723722
if (t == LDOUBLE && !allow_c90)
724723
/* 'long double' requires C90 or later */
725724
warning(266);
725+
if (t == COMPLEX && c == FLOAT)
726+
t = FCOMPLEX;
727+
else if (t == COMPLEX && c == DOUBLE)
728+
t = DCOMPLEX;
729+
else if (t == COMPLEX && c == LDOUBLE)
730+
t = LCOMPLEX;
731+
else if (t == COMPLEX) {
732+
/* invalid type for _Complex */
733+
error(308);
734+
t = DCOMPLEX;
735+
}
726736
if (l == LONG && t == DCOMPLEX) {
727737
l = NO_TSPEC;
728738
t = LCOMPLEX;

0 commit comments

Comments
 (0)