Skip to content

Commit 038edf6

Browse files
committed
Don't reject uses of void-returning consteval functions.
1 parent cca3f3d commit 038edf6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,10 @@ static bool
22992299
CheckConstantExpression(EvalInfo &Info, SourceLocation DiagLoc, QualType Type,
23002300
const APValue &Value,
23012301
Expr::ConstExprUsage Usage = Expr::EvaluateForCodeGen) {
2302+
// Nothing to check for a constant expression of type 'cv void'.
2303+
if (Type->isVoidType())
2304+
return true;
2305+
23022306
CheckedTemporaries CheckedTemps;
23032307
return CheckEvaluationResult(CheckEvaluationResultKind::ConstantExpression,
23042308
Info, DiagLoc, Type, Value, Usage,

clang/test/SemaCXX/consteval-return-void.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ template <typename T> constexpr E operator*(E,E);
1818
template <typename T> consteval E operator/(E,E);
1919
template <> constexpr E operator*<int>(E,E) { return; } // expected-error {{non-void constexpr function 'operator*<int>' should return a value}}
2020
template <> consteval E operator/<int>(E,E) { return; } // expected-error {{non-void consteval function 'operator/<int>' should return a value}}
21+
22+
consteval void no_return() {}
23+
consteval void with_return() { return; }
24+
consteval void with_return_void() { return void(); }
25+
void use_void_fn() {
26+
no_return();
27+
with_return();
28+
with_return_void();
29+
}

0 commit comments

Comments
 (0)