================
@@ -1832,6 +1832,33 @@ static ExprResult BuiltinLaunder(Sema &S, CallExpr 
*TheCall) {
   return TheCall;
 }
 
+static ExprResult BuiltinIsWithinLifetime(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+    return ExprError();
+
+  ExprResult Arg = S.DefaultFunctionArrayLvalueConversion(TheCall->getArg(0));
+  if (Arg.isInvalid())
+    return ExprError();
+  QualType ParamTy = Arg.get()->getType();
+  TheCall->setArg(0, Arg.get());
+  TheCall->setType(S.Context.BoolTy);
+
+  // A call to this function is always ill-formed if the type is not a pointer
+  // to an object type. There is no Mandates: to that effect, so we can only
+  // issue an error if it is actually evaluated as part of a constant 
evaluation
+  // (e.g., `false ? true :
----------------
MitalAshok wrote:

You can write `std::is_within_lifetime<int()>(&function)` 
(https://compiler-explorer.com/z/GYn1sEjd8). It's not too much of a hassle to 
accept function pointers and fail them later since they have the same 
representation as object pointers during constant evaluation

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

Reply via email to