Skip to content

[clang] Allow constexpr-unknown values pre C++23 #129646

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Mar 4, 2025

Let's check the CI.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Let's check the CI.


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

1 Files Affected:

  • (modified) clang/lib/AST/ExprConstant.cpp (+2-4)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6ccb6e23f8d2f..9ea42b308f42c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3470,8 +3470,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
                                 unsigned Version, APValue *&Result) {
   // C++23 [expr.const]p8 If we have a reference type allow unknown references
   // and pointers.
-  bool AllowConstexprUnknown =
-      Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType();
+  bool AllowConstexprUnknown = VD->getType()->isReferenceType();
 
   APValue::LValueBase Base(VD, Frame ? Frame->Index : 0, Version);
 
@@ -8893,8 +8892,7 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
 bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
   // C++23 [expr.const]p8 If we have a reference type allow unknown references
   // and pointers.
-  bool AllowConstexprUnknown =
-      Info.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType();
+  bool AllowConstexprUnknown = VD->getType()->isReferenceType();
   // If we are within a lambda's call operator, check whether the 'VD' referred
   // to within 'E' actually represents a lambda-capture that maps to a
   // data-member/field within the closure object, and if so, evaluate to the

@tbaederr tbaederr changed the title [clang] Alloc constexpr-unknown values pre C++23 [clang] Allow constexpr-unknown values pre C++23 Mar 4, 2025
@frederick-vs-ja frederick-vs-ja added the defect report Issues representing WG21 papers to be applied as a defect report label Mar 4, 2025
@tbaederr
Copy link
Contributor Author

tbaederr commented Mar 4, 2025

Looks like the differences are mainly that we don't emit the "unknown/invalid initializer" diagnostics anymore.

@cor3ntin
Copy link
Contributor

cor3ntin commented Mar 4, 2025

@frederick-vs-ja AFAIK, this would be an extension, NOT a DR.

We probably want to be reasonably conservative here, because there are known issues with the implementation
(#127475)

@frederick-vs-ja frederick-vs-ja removed the defect report Issues representing WG21 papers to be applied as a defect report label Mar 4, 2025
@frederick-vs-ja
Copy link
Contributor

@cor3ntin I see... My opinion is because N4916 said the P2280R4 was accepted as a DR and GCC is so treating it. Not sure whether the divergence would be desired.

@cor3ntin
Copy link
Contributor

cor3ntin commented Mar 4, 2025

@cor3ntin I see... My opinion is because N4916 said the P2280R4 was accepted as a DR and GCC is so treating it. Not sure whether the divergence would be desired.

You are right, I updated https://clang.llvm.org/cxx_status.html#cxx23

I still think we should wait a bit for the codegen bugs to be fixed first

@shafik
Copy link
Collaborator

shafik commented Mar 7, 2025

@cor3ntin I see... My opinion is because N4916 said the P2280R4 was accepted as a DR and GCC is so treating it. Not sure whether the divergence would be desired.

You are right, I updated https://clang.llvm.org/cxx_status.html#cxx23

I still think we should wait a bit for the codegen bugs to be fixed first

I am still recovering from being sick but I agree, we should probably hold off for a bit more.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Mar 14, 2025

The reduction of diagnostic messages in OpenMP tests seems like a good thing to me. IMO there's no initialization in #pragma omp parallel masked taskloop simd aligned(f:j) and its friends.
But other test failures probably indicated remaining bugs.

Edit: The behavioral change of clangd is also probably a good thing!

@efriedma-quic
Copy link
Collaborator

Reduced testcase for the microsoft-abi-member-pointers.cpp failure:

constinit int &b = b;

This should produce an error; clang -std=c++23 currently accepts it.

@efriedma-quic
Copy link
Collaborator

The other test changes look mostly okay, but worth investigating to see if we can improve the diagnostic notes for illegal uses of constexpr-unknown variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants