Skip to content

Commit

Permalink
Don't reject uses of void-returning consteval functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
zygoloid committed Aug 20, 2020
1 parent cca3f3d commit 038edf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions clang/test/SemaCXX/consteval-return-void.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 038edf6

Please sign in to comment.