Skip to content

Conversation

AaronBallman
Copy link
Collaborator

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.

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.
@AaronBallman AaronBallman added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" c2y labels Oct 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/162877.diff

4 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/lib/Sema/SemaExpr.cpp (+5-1)
  • (added) clang/test/C/C2y/n3622.c (+20)
  • (modified) clang/www/c_status.html (+1-1)
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}}
+}
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>

@AaronBallman AaronBallman merged commit 8e60adc into llvm:main Oct 10, 2025
10 of 11 checks passed
@AaronBallman AaronBallman deleted the aballman-wg14-n3622 branch October 10, 2025 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c2y clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants