Skip to content

Commit 1bd2f01

Browse files
committed
update C2x diagnostic handling logic
1 parent 417f3c9 commit 1bd2f01

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,9 +1621,11 @@ QualType Sema::BuildQualifiedType(QualType T, SourceLocation Loc,
16211621
Diag(Loc, DiagID) << EltTy;
16221622
Qs.removeRestrict();
16231623
} else {
1624-
if (!getLangOpts().C23 && T->isArrayType()) {
1625-
Diag(Loc, diag::ext_restrict_on_array_of_pointers_c23);
1626-
Diag(Loc, diag::warn_c23_compat_restrict_on_array_of_pointers);
1624+
if (T->isArrayType()) {
1625+
if (getLangOpts().C23)
1626+
Diag(Loc, diag::warn_c23_compat_restrict_on_array_of_pointers);
1627+
else
1628+
Diag(Loc, diag::ext_restrict_on_array_of_pointers_c23);
16271629
}
16281630
}
16291631
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
22
// RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -verify=pedantic %s
3-
// RUN: %clang_cc1 -std=c17 -fsyntax-only -Wpre-c2x-compat -verify=pre-c2x-compat %s
3+
// RUN: %clang_cc1 -std=c2x -fsyntax-only -Wpre-c2x-compat -verify=c2x-compat %s
44

55
typedef int (*T1)[2];
66
restrict T1 t1;
77

88
typedef int *T2[2];
99
restrict T2 t2; // pedantic-warning {{'restrict' qualifier on an array of pointers is a C23 extension}} \
10-
// pre-c2x-compat-warning {{'restrict' qualifier on an array of pointers is incompatible with C standards before C23}}
10+
// c2x-compat-warning {{'restrict' qualifier on an array of pointers is incompatible with C standards before C23}}
1111

1212
typedef int *T3[2][2];
1313
restrict T3 t3; // pedantic-warning {{'restrict' qualifier on an array of pointers is a C23 extension}} \
14-
// pre-c2x-compat-warning {{'restrict' qualifier on an array of pointers is incompatible with C standards before C23}}
14+
// c2x-compat-warning {{'restrict' qualifier on an array of pointers is incompatible with C standards before C23}}
1515

1616
typedef int (*t4)(); // pedantic-warning {{a function declaration without a prototype is deprecated in all versions of C}}
1717
typedef t4 t5[2];
1818
typedef t5 restrict t6; // expected-error {{pointer to function type 'int (void)' may not be 'restrict' qualified}} \
1919
// pedantic-error {{pointer to function type 'int ()' may not be 'restrict' qualified}} \
20-
// pre-c2x-compat-error {{pointer to function type 'int ()' may not be 'restrict' qualified}}
20+
// c2x-compat-error {{pointer to function type 'int (void)' may not be 'restrict' qualified}}
2121

2222
typedef int t7[2];
2323
typedef t7 restrict t8; // expected-error {{restrict requires a pointer or reference ('t7' (aka 'int[2]') is invalid)}} \
2424
// pedantic-error {{restrict requires a pointer or reference ('t7' (aka 'int[2]') is invalid)}} \
25-
// pre-c2x-compat-error {{restrict requires a pointer or reference ('t7' (aka 'int[2]') is invalid}}
25+
// c2x-compat-error {{restrict requires a pointer or reference ('t7' (aka 'int[2]') is invalid}}

0 commit comments

Comments
 (0)