[clang] [Clang][C++23] update constexpr diagnostics for missing return statements per P2448 (PR #94123)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 4 01:25:01 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.
----------------
Fznamznon wrote:
Could you please also mention that we early-exit and don't emit error diagnostic in C++23 because it doesn't require `constexpr` function to produce a constant expression?
https://github.com/llvm/llvm-project/pull/94123
More information about the cfe-commits
mailing list