[clang] 038edf6 - Don't reject uses of void-returning consteval functions.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 20 15:40:22 PDT 2020
Author: Richard Smith
Date: 2020-08-20T15:40:09-07:00
New Revision: 038edf6029bafe70b1f7165abe2b0e61ddf506b3
URL: https://github.com/llvm/llvm-project/commit/038edf6029bafe70b1f7165abe2b0e61ddf506b3
DIFF: https://github.com/llvm/llvm-project/commit/038edf6029bafe70b1f7165abe2b0e61ddf506b3.diff
LOG: Don't reject uses of void-returning consteval functions.
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/consteval-return-void.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 2c2dd6a3ef3a..b22797b5c3c0 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 39e1418306f5..da1fd8b7cdf7 100644
--- a/clang/test/SemaCXX/consteval-return-void.cpp
+++ b/clang/test/SemaCXX/consteval-return-void.cpp
@@ -18,3 +18,12 @@ template <typename T> constexpr E operator*(E,E);
template <typename T> consteval E operator/(E,E);
template <> constexpr E operator*<int>(E,E) { return; } // expected-error {{non-void constexpr function 'operator*<int>' should return a value}}
template <> consteval E operator/<int>(E,E) { return; } // expected-error {{non-void consteval function 'operator/<int>' 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();
+}
More information about the cfe-commits
mailing list