Skip to content

Commit 16494be

Browse files
authored
[clang][bytecode] Reject dependent RequiresExprs (llvm#155230)
Fixes llvm#152899
1 parent 75b36d0 commit 16494be

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,6 +3895,8 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
38953895
template <class Emitter>
38963896
bool Compiler<Emitter>::VisitRequiresExpr(const RequiresExpr *E) {
38973897
assert(classifyPrim(E->getType()) == PT_Bool);
3898+
if (E->isValueDependent())
3899+
return false;
38983900
if (DiscardResult)
38993901
return true;
39003902
return this->emitConstBool(E->isSatisfied(), E);

clang/test/AST/ByteCode/cxx2a.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,17 @@ namespace GH150705 {
239239
constexpr const A& a = b;
240240
constexpr auto x = (a.*q)(); // both-error {{constant expression}}
241241
}
242+
243+
namespace DependentRequiresExpr {
244+
template <class T,
245+
bool = []() -> bool { // both-error {{not a constant expression}}
246+
if (requires { T::type; })
247+
return true;
248+
return false;
249+
}()>
250+
struct p {
251+
using type = void;
252+
};
253+
254+
template <class T> using P = p<T>::type; // both-note {{while checking a default template argument}}
255+
}

0 commit comments

Comments
 (0)