From 038edf6029bafe70b1f7165abe2b0e61ddf506b3 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 20 Aug 2020 15:34:34 -0700 Subject: [PATCH] Don't reject uses of void-returning consteval functions. --- clang/lib/AST/ExprConstant.cpp | 4 ++++ clang/test/SemaCXX/consteval-return-void.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 2c2dd6a..b22797b 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2299,6 +2299,10 @@ static bool CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc, QualType Type, const APValue &Value, Expr::ConstExprUsage Usage = Expr::EvaluateForCodeGen) { + // Nothing to check for a constant expression of type 'cv void'. + if (Type->isVoidType()) + return true; + CheckedTemporaries CheckedTemps; return CheckEvaluationResult(CheckEvaluationResultKind::ConstantExpression, Info, DiagLoc, Type, Value, Usage, diff --git a/clang/test/SemaCXX/consteval-return-void.cpp b/clang/test/SemaCXX/consteval-return-void.cpp index 39e1418..da1fd8b 100644 --- a/clang/test/SemaCXX/consteval-return-void.cpp +++ b/clang/test/SemaCXX/consteval-return-void.cpp @@ -18,3 +18,12 @@ template constexpr E operator*(E,E); template consteval E operator/(E,E); template <> constexpr E operator*(E,E) { return; } // expected-error {{non-void constexpr function 'operator*' should return a value}} template <> consteval E operator/(E,E) { return; } // expected-error {{non-void consteval function 'operator/' should return a value}} + +consteval void no_return() {} +consteval void with_return() { return; } +consteval void with_return_void() { return void(); } +void use_void_fn() { + no_return(); + with_return(); + with_return_void(); +} -- 2.7.4