Skip to content

Commit b3e0949

Browse files
committed
[C2y] Implement WG14 N3622 static used in an inline
This paper removes the constraint that a static variable or function cannot be used within an extern inline function. The diagnostic is still being produced in earlier language modes for conformance reasons but has always been accepted as an extension.
1 parent f6caec6 commit b3e0949

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ C Language Changes
180180

181181
C2y Feature Support
182182
^^^^^^^^^^^^^^^^^^^
183+
- No longer triggering ``-Wstatic-in-inline`` in C2y mode; use of a static
184+
function or variable within an extern inline function is no longer a
185+
constraint per `WG14 N3622 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3622.txt>`_.
183186
- Clang now supports `N3355 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm>`_ Named Loops.
184187

185188
C23 Feature Support

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ static void diagnoseUseOfInternalDeclInInlineFunction(Sema &S,
166166
// This is disabled under C++; there are too many ways for this to fire in
167167
// contexts where the warning is a false positive, or where it is technically
168168
// correct but benign.
169-
if (S.getLangOpts().CPlusPlus)
169+
//
170+
// This is also disabled in C2y because of WG14 N3622 which removed the
171+
// constraint entirely. It is left enabled in earlier language modes because
172+
// this is a constraint in those language modes.
173+
if (S.getLangOpts().CPlusPlus || S.getLangOpts().C2y)
170174
return;
171175

172176
// Check if this is an inlined function or method.

clang/test/C/C2y/n3622.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -verify=good -pedantic -Wall -std=c2y %s
2+
// RUN: %clang_cc1 -verify -pedantic -Wall -std=c23 %s
3+
// RUN: %clang_cc1 -verify -pedantic -Wall -std=c17 %s
4+
// good-no-diagnostics
5+
6+
/* WG14 N3622: Clang 22
7+
* Allow calling static inline within extern inline
8+
*
9+
* This verifies that a constraint from previous standards is no longer
10+
* triggered in C2y mode. The constraint is with calling a statric function
11+
* or using a static variable from an inline function with external linkage.
12+
*/
13+
14+
static void static_func(void) {} // expected-note {{declared here}}
15+
static int static_var; // expected-note {{declared here}}
16+
17+
extern inline void test(void) {
18+
static_func(); // expected-warning {{static function 'static_func' is used in an inline function with external linkage}}
19+
static_var = 12; // expected-warning {{static variable 'static_var' is used in an inline function with external linkage}}
20+
}

0 commit comments

Comments
 (0)