-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[C2y] Implement WG14 N3622 static used in an inline #162877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
@llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) ChangesThis 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:
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>
|
erichkeane
reviewed
Oct 10, 2025
erichkeane
approved these changes
Oct 10, 2025
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.