[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:10:29 PDT 2025
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/162877
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.
>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] [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}}
+}
More information about the cfe-commits
mailing list