[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-05 Thread via llvm-branch-commits

github-actions[bot] wrote:

@AaronBallman (or anyone else). If you would like to add a note about this fix 
in the release notes (completely optional). Please reply to this comment with a 
one or two sentence description of the fix.  When you are done, please add the 
release:note label to this PR. 

https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-05 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru closed https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-05 Thread Tobias Hieta via llvm-branch-commits

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/151999

>From d502822e682a1147e64e63ae93af2e8f794f05b0 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 4 Aug 2025 12:46:53 -0400
Subject: [PATCH] [C] static_assert in a for loop is not an extension (#151955)

The original wording can be squinted at to pretend this was always
allowed. GCC squints at it that way, so we're doing the same and no
longer issuing an extension diagnostic for use of static_assert in the
condition-1 of a for loop in C.

Fixes #149633

(cherry picked from commit cb50d78a0063244434d883d89ddda7f74abbffc9)
---
 clang/lib/Sema/SemaStmt.cpp | 6 +-
 clang/test/Sema/for.c   | 3 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f85826aecadf3..f46be75bda20f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2287,7 +2287,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // we can diagnose if we don't see any variable declarations. This
   // covers a case like declaring a typedef, function, or structure
   // type rather than a variable.
-  NonVarSeen = DI;
+  //
+  // Note, _Static_assert is acceptable because it does not declare an
+  // identifier at all, so "for object having" does not apply.
+  if (!isa(DI))
+NonVarSeen = DI;
 }
   }
   // Diagnose if we saw a non-variable declaration but no variable
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index e16169aac0c4c..35c4720ef3305 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } 
s;s.i;); } /* c11-
 #endif
 
 void b12(void) {
-  for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 
'for' loop is a C23 extension}}
- c23-warning {{non-variable declaration in 
'for' loop is incompatible with C standards before C23}} */
+  for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* 
identifiers */
 }

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread Corentin Jabot via llvm-branch-commits

https://github.com/cor3ntin approved this pull request.


https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

https://github.com/Sirraide approved this pull request.


https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:

@cor3ntin What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport cb50d78

Requested by: @AaronBallman

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaStmt.cpp (+5-1) 
- (modified) clang/test/Sema/for.c (+1-2) 


``diff
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f85826aecadf3..f46be75bda20f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2287,7 +2287,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // we can diagnose if we don't see any variable declarations. This
   // covers a case like declaring a typedef, function, or structure
   // type rather than a variable.
-  NonVarSeen = DI;
+  //
+  // Note, _Static_assert is acceptable because it does not declare an
+  // identifier at all, so "for object having" does not apply.
+  if (!isa(DI))
+NonVarSeen = DI;
 }
   }
   // Diagnose if we saw a non-variable declaration but no variable
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index e16169aac0c4c..35c4720ef3305 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } 
s;s.i;); } /* c11-
 #endif
 
 void b12(void) {
-  for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 
'for' loop is a C23 extension}}
- c23-warning {{non-variable declaration in 
'for' loop is incompatible with C standards before C23}} */
+  for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* 
identifiers */
 }

``




https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/151999
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/21.x: [C] static_assert in a for loop is not an extension (#151955) (PR #151999)

2025-08-04 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/151999

Backport cb50d78

Requested by: @AaronBallman

>From 8c4a9ae3b05636463ae2d24600ab4345d943a502 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 4 Aug 2025 12:46:53 -0400
Subject: [PATCH] [C] static_assert in a for loop is not an extension (#151955)

The original wording can be squinted at to pretend this was always
allowed. GCC squints at it that way, so we're doing the same and no
longer issuing an extension diagnostic for use of static_assert in the
condition-1 of a for loop in C.

Fixes #149633

(cherry picked from commit cb50d78a0063244434d883d89ddda7f74abbffc9)
---
 clang/lib/Sema/SemaStmt.cpp | 6 +-
 clang/test/Sema/for.c   | 3 +--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f85826aecadf3..f46be75bda20f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2287,7 +2287,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // we can diagnose if we don't see any variable declarations. This
   // covers a case like declaring a typedef, function, or structure
   // type rather than a variable.
-  NonVarSeen = DI;
+  //
+  // Note, _Static_assert is acceptable because it does not declare an
+  // identifier at all, so "for object having" does not apply.
+  if (!isa(DI))
+NonVarSeen = DI;
 }
   }
   // Diagnose if we saw a non-variable declaration but no variable
diff --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index e16169aac0c4c..35c4720ef3305 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -26,6 +26,5 @@ void b11 (void) { for (static _Thread_local struct { int i; } 
s;s.i;); } /* c11-
 #endif
 
 void b12(void) {
-  for(_Static_assert(1, "");;) {} /* c11-warning {{non-variable declaration in 
'for' loop is a C23 extension}}
- c23-warning {{non-variable declaration in 
'for' loop is incompatible with C standards before C23}} */
+  for(_Static_assert(1, "");;) {} /* okay, _Static_assert declares *no* 
identifiers */
 }

___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits