Skip to content

Conversation

tbaederr
Copy link
Contributor

Fixes #152899

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Aug 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 25, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Fixes #152899


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

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
  • (modified) clang/test/AST/ByteCode/cxx2a.cpp (+14)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index e3235d34e230e..a98c0acb4f660 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3879,6 +3879,8 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
 template <class Emitter>
 bool Compiler<Emitter>::VisitRequiresExpr(const RequiresExpr *E) {
   assert(classifyPrim(E->getType()) == PT_Bool);
+  if (E->isValueDependent())
+    return false;
   if (DiscardResult)
     return true;
   return this->emitConstBool(E->isSatisfied(), E);
diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp
index 744c99eaa1e68..533173d84792f 100644
--- a/clang/test/AST/ByteCode/cxx2a.cpp
+++ b/clang/test/AST/ByteCode/cxx2a.cpp
@@ -239,3 +239,17 @@ namespace GH150705 {
   constexpr const A& a = b;
   constexpr auto x = (a.*q)(); // both-error {{constant expression}}
 }
+
+namespace DependentRequiresExpr {
+  template <class T,
+            bool = []() -> bool { // both-error {{not a constant expression}}
+              if (requires { T::type; })
+                return true;
+              return false;
+            }()>
+  struct p {
+    using type = void;
+  };
+
+  template <class T> using P = p<T>::type; // both-note {{while checking a default template argument}}
+}

Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know which clause causes clang to choose to reject this, looks like we are the only one: https://godbolt.org/z/KhfeP5W6d

CC @hokein looks like came in w/ bd4662c

@tbaederr
Copy link
Contributor Author

Do you know which clause causes clang to choose to reject this, looks like we are the only one: https://godbolt.org/z/KhfeP5W6d

CC @hokein looks like came in w/ bd4662c

No clue. The RequiresExpr ends up being dependent, but that does not end up being propagated to any parent nodes, so none of the previous dependency checks works. Whether the RequiresExpr (or its SimpleRequirement) should be dependent at all, I don't know.

@tbaederr tbaederr merged commit 16494be into llvm:main Aug 27, 2025
9 checks passed
@shafik
Copy link
Collaborator

shafik commented Aug 27, 2025

CC @zygoloid is clang correct to reject the example in this code?

@zygoloid
Copy link
Collaborator

I don't see why that would be invalid. When forming p<T>::type, we should produce a default argument for p by substituting T = T into the specified default argument. That should produce a value-dependent initializer, which is fine, but makes p<T> a dependent type. So p<T>::type should be interpreted as a dependent type-id.

@zygoloid
Copy link
Collaborator

Looks like the problem is not a RequiresExpr issue at all, it's a problem with how we handle partial substitution into lambdas. Reduced to a crash on valid: https://godbolt.org/z/n46Knan3v

@shafik
Copy link
Collaborator

shafik commented Aug 28, 2025

CC @cor3ntin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter 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.

[clang][bytecode] Assertion `!isValueDependent() && "isSatisfied called on a dependent RequiresExpr"' failed
4 participants