[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)

Oleksandr T. via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 4 12:03:20 PDT 2024


================
@@ -2487,6 +2477,26 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl,
   return true;
 }
 
+static bool CheckConstexprMissingReturn(Sema &SemaRef,
+                                        const FunctionDecl *Dcl) {
+  bool IsVoidOrDependentType = Dcl->getReturnType()->isVoidType() ||
+                               Dcl->getReturnType()->isDependentType();
+
+  if (SemaRef.getLangOpts().CPlusPlus23 && !IsVoidOrDependentType)
+    return true;
+
+  // C++1y doesn't require constexpr functions to contain a 'return'
+  // statement. We still do, unless the return type might be void, because
+  // otherwise if there's no return statement, the function cannot
+  // be used in a core constant expression.
----------------
a-tarasyuk wrote:

@Fznamznon Thanks for the review. I've added a comment.

https://github.com/llvm/llvm-project/pull/94123


More information about the cfe-commits mailing list