[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-11 Thread Oleksandr T. via cfe-commits


@@ -2203,8 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}

a-tarasyuk wrote:

@zyn0217 Thanks for the suggestion. I've added changes.

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-11 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/7] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/7] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/7] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/7] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk closed 
https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Younan Zhang via cfe-commits

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


https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/7] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/7] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/7] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/7] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/6] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/6] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/6] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/6] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Oleksandr T. via cfe-commits


@@ -309,6 +309,7 @@ Bug Fixes to AST Handling
 ^
 - Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
 - Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. 
(#GH129198)
+- Clang now correctly parses ``if constexpr`` expressions in immediate 
function context. (#GH123524)

a-tarasyuk wrote:

Thanks. I've moved to `Bug fixes to C++ support` section

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-09 Thread Younan Zhang via cfe-commits


@@ -309,6 +309,7 @@ Bug Fixes to AST Handling
 ^
 - Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
 - Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. 
(#GH129198)
+- Clang now correctly parses ``if constexpr`` expressions in immediate 
function context. (#GH123524)

zyn0217 wrote:

This should go in the "Bug fixes to C++ support" column

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-07 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/5] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/5] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/5] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/5] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-06 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk deleted 
https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-05 Thread via cfe-commits

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


https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-03-05 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/5] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/5] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/5] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/5] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-02-27 Thread Younan Zhang via cfe-commits


@@ -2203,8 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}

zyn0217 wrote:

```suggestion
ExprResult Expr = [&] {
  EnterExpressionEvaluationContext Eval(
  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
  /*LambdaContextDecl=*/nullptr,
  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);

  // Parse the expression.
  return ParseExpression(); // expression
}();
```

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-02-20 Thread Erich Keane via cfe-commits

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

This now lacks my concerns, as this is only applying to the singular 
expression.  But parsing isn't my expertise, so @cor3ntin or @Endilll should 
probably think about this for a minute or two.

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-02-19 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk edited 
https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-24 Thread Younan Zhang via cfe-commits


@@ -977,6 +977,7 @@ Bug Fixes to C++ Support
 - Fix immediate escalation not propagating through inherited constructors.  
(#GH112677)
 - Fixed assertions or false compiler diagnostics in the case of C++ modules for
   lambda functions or inline friend functions defined inside templates 
(#GH122493).
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)

zyn0217 wrote:

If possible, I'd like to ask you to consolidate the note with line 977.

AFAIK this isn't the first time we start to allow the use of immediate 
functions within `if constexpr` statements. For example, we've already been 
accepting code like this

```cpp
consteval bool fn() {
  return true;
}

void fn2() {
if constexpr (fn()) {}
}

```

So the phrase "now permits" is inaccurate in these scenarios

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-24 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/2] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d60..cd16ce13a4e6b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42a..e174d9a24e7440 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 00..1832086fee42d4
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/2] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d4..494fc45c55c4e0 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-22 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik requested changes to this pull request.

Please add a more detailed summary to this PR. I have asked this on several PRs 
and I believe the confusion reflected in the comments is very much attributed 
to not explaining why you believe your fix works. It may be incorrect but a 
solid summary will allow the reviewers to quickly understand the assumptions 
you are making in your fix and should reduce back and forth and allow for more 
targeted feedback quicker.

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Erich Keane via cfe-commits


@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(

erichkeane wrote:

Right, I saw that/understand how that 'ShouldEnter' works.  its just not clear 
to me that this is the correct place that the context should be introduced.

It isn't clear to me why it is introduced only for `Expression` and not an 
`InitStmtDecl` for example.  And also why it should apply to the expression AND 
condition (on 2213 and 2221 respectively) but not the condition on 2203, etc.

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Oleksandr T. via cfe-commits


@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(

a-tarasyuk wrote:

This context will be applied only for `ConstexprIf`. It uses the `ShouldEnter` 
flag to control the pushing of the extra context, all other kinds will be 
ignored

https://github.com/llvm/llvm-project/blob/e1c1e74a6fd71dd889155100d4c0f5e3284f7a22/clang/include/clang/Sema/EnterExpressionEvaluationContext.h#L29-L33

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Erich Keane via cfe-commits


@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(

erichkeane wrote:

No, more that this applies to the expressoin on 2213 as well as the 
CXXCondition on 2221 (which looks like a recursive call?).  I just want to make 
sure we're not applying this context to stuff that it shouldn't be here.  

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Oleksandr T. via cfe-commits


@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(

a-tarasyuk wrote:

Do you mean using the extra context for this case would introduce unnecessary 
overhead? Should the `if constexpr` be parsed within the same context, but with 
different parsing logic?

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Erich Keane via cfe-commits


@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(

erichkeane wrote:

This doesn't quite seem right to me, as it is covering parsing at least 2 
things, do we really intend that? 

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk edited 
https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s

a-tarasyuk wrote:

@frederick-vs-ja I've updated the test

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-21 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/123667

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/2] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d60..cd16ce13a4e6b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42a..e174d9a24e7440 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 00..1832086fee42d4
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/2] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d4..494fc45c55c4e0 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-20 Thread A. Jiang via cfe-commits


@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s

frederick-vs-ja wrote:

I think it would be better to verify that this is OK since C++20.

https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #123524

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1-1) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+6) 
- (added) clang/test/SemaCXX/constexpr-if.cpp (+10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d60..cd16ce13a4e6b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42a..e174d9a24e7440 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 00..1832086fee42d4
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

``




https://github.com/llvm/llvm-project/pull/123667
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

2025-01-20 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/123667

Fixes #123524

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d60..cd16ce13a4e6b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42a..e174d9a24e7440 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 00..1832086fee42d4
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits