[clang] [C2y] Implement WG14 N3622 static used in an inline (PR #162877)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 09:26:16 PDT 2025
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/162877
>From b3e094947fefa338e920adf8ec51360251e343c6 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Fri, 10 Oct 2025 12:08:00 -0400
Subject: [PATCH 1/3] [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.
---
clang/docs/ReleaseNotes.rst | 3 +++
clang/lib/Sema/SemaExpr.cpp | 6 +++++-
clang/test/C/C2y/n3622.c | 20 ++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 clang/test/C/C2y/n3622.c
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 99aa545831240..65b086caf3652 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -180,6 +180,9 @@ C Language Changes
C2y Feature Support
^^^^^^^^^^^^^^^^^^^
+- No longer triggering ``-Wstatic-in-inline`` in C2y mode; use of a static
+ function or variable within an extern inline function is no longer a
+ constraint per `WG14 N3622 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3622.txt>`_.
- Clang now supports `N3355 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm>`_ Named Loops.
C23 Feature Support
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4230ea702e128..efb064c6de913 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -166,7 +166,11 @@ static void diagnoseUseOfInternalDeclInInlineFunction(Sema &S,
// This is disabled under C++; there are too many ways for this to fire in
// contexts where the warning is a false positive, or where it is technically
// correct but benign.
- if (S.getLangOpts().CPlusPlus)
+ //
+ // This is also disabled in C2y because of WG14 N3622 which removed the
+ // constraint entirely. It is left enabled in earlier language modes because
+ // this is a constraint in those language modes.
+ if (S.getLangOpts().CPlusPlus || S.getLangOpts().C2y)
return;
// Check if this is an inlined function or method.
diff --git a/clang/test/C/C2y/n3622.c b/clang/test/C/C2y/n3622.c
new file mode 100644
index 0000000000000..4ef6d81ec40f9
--- /dev/null
+++ b/clang/test/C/C2y/n3622.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify=good -pedantic -Wall -std=c2y %s
+// RUN: %clang_cc1 -verify -pedantic -Wall -std=c23 %s
+// RUN: %clang_cc1 -verify -pedantic -Wall -std=c17 %s
+// good-no-diagnostics
+
+/* WG14 N3622: Clang 22
+ * Allow calling static inline within extern inline
+ *
+ * This verifies that a constraint from previous standards is no longer
+ * triggered in C2y mode. The constraint is with calling a statric function
+ * or using a static variable from an inline function with external linkage.
+ */
+
+static void static_func(void) {} // expected-note {{declared here}}
+static int static_var; // expected-note {{declared here}}
+
+extern inline void test(void) {
+ static_func(); // expected-warning {{static function 'static_func' is used in an inline function with external linkage}}
+ static_var = 12; // expected-warning {{static variable 'static_var' is used in an inline function with external linkage}}
+}
>From 76012328a7f21a81b1e48c056f0aefe831a10cb2 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Fri, 10 Oct 2025 12:09:50 -0400
Subject: [PATCH 2/3] Update website too
---
clang/www/c_status.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index a6bcd4c197133..b8039622fe694 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -349,7 +349,7 @@ <h2 id="c2y">C2y implementation status</h2>
<tr>
<td>Allow calling static inline within extern inline</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3622.txt">N3622</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="unreleased" align="center">Clang 22</td>
</tr>
<tr>
<td>Generic replacement (v. 2 of quasi-literals)</td>
>From 22d74870362438fcebed3826efa4a5a455223c77 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Fri, 10 Oct 2025 12:23:15 -0400
Subject: [PATCH 3/3] Fix typo; NFC
---
clang/test/C/C2y/n3622.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/C/C2y/n3622.c b/clang/test/C/C2y/n3622.c
index 4ef6d81ec40f9..daacf64dbf795 100644
--- a/clang/test/C/C2y/n3622.c
+++ b/clang/test/C/C2y/n3622.c
@@ -7,7 +7,7 @@
* Allow calling static inline within extern inline
*
* This verifies that a constraint from previous standards is no longer
- * triggered in C2y mode. The constraint is with calling a statric function
+ * triggered in C2y mode. The constraint is with calling a static function
* or using a static variable from an inline function with external linkage.
*/
More information about the cfe-commits
mailing list