@@ -6123,61 +6123,6 @@ static ExprResult BuildConvertedConstantExpression(Sema &S, Expr *From,
6123
6123
return Result;
6124
6124
}
6125
6125
6126
- /// EvaluateConvertedConstantExpression - Evaluate an Expression
6127
- /// That is a converted constant expression
6128
- /// (which was built with BuildConvertedConstantExpression)
6129
- static ExprResult EvaluateConvertedConstantExpression(
6130
- Sema &S, Expr *E, QualType T, APValue &Value, Sema::CCEKind CCE,
6131
- bool RequireInt, const APValue &PreNarrowingValue) {
6132
- ExprResult Result = E;
6133
- // Check the expression is a constant expression.
6134
- SmallVector<PartialDiagnosticAt, 8> Notes;
6135
- Expr::EvalResult Eval;
6136
- Eval.Diag = &Notes;
6137
-
6138
- ConstantExprKind Kind;
6139
- if (CCE == Sema::CCEK_TemplateArg && T->isRecordType())
6140
- Kind = ConstantExprKind::ClassTemplateArgument;
6141
- else if (CCE == Sema::CCEK_TemplateArg)
6142
- Kind = ConstantExprKind::NonClassTemplateArgument;
6143
- else
6144
- Kind = ConstantExprKind::Normal;
6145
-
6146
- if (!E->EvaluateAsConstantExpr(Eval, S.Context, Kind) ||
6147
- (RequireInt && !Eval.Val.isInt())) {
6148
- // The expression can't be folded, so we can't keep it at this position in
6149
- // the AST.
6150
- Result = ExprError();
6151
- } else {
6152
- Value = Eval.Val;
6153
-
6154
- if (Notes.empty()) {
6155
- // It's a constant expression.
6156
- Expr *E = ConstantExpr::Create(S.Context, Result.get(), Value);
6157
- if (!PreNarrowingValue.isAbsent())
6158
- Value = std::move(PreNarrowingValue);
6159
- return E;
6160
- }
6161
- }
6162
-
6163
- // It's not a constant expression. Produce an appropriate diagnostic.
6164
- if (Notes.size() == 1 &&
6165
- Notes[0].second.getDiagID() == diag::note_invalid_subexpr_in_const_expr) {
6166
- S.Diag(Notes[0].first, diag::err_expr_not_cce) << CCE;
6167
- } else if (!Notes.empty() && Notes[0].second.getDiagID() ==
6168
- diag::note_constexpr_invalid_template_arg) {
6169
- Notes[0].second.setDiagID(diag::err_constexpr_invalid_template_arg);
6170
- for (unsigned I = 0; I < Notes.size(); ++I)
6171
- S.Diag(Notes[I].first, Notes[I].second);
6172
- } else {
6173
- S.Diag(E->getBeginLoc(), diag::err_expr_not_cce)
6174
- << CCE << E->getSourceRange();
6175
- for (unsigned I = 0; I < Notes.size(); ++I)
6176
- S.Diag(Notes[I].first, Notes[I].second);
6177
- }
6178
- return ExprError();
6179
- }
6180
-
6181
6126
/// CheckConvertedConstantExpression - Check that the expression From is a
6182
6127
/// converted constant expression of type T, perform the conversion and produce
6183
6128
/// the converted expression, per C++11 [expr.const]p3.
@@ -6194,8 +6139,8 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
6194
6139
Value = APValue();
6195
6140
return Result;
6196
6141
}
6197
- return EvaluateConvertedConstantExpression(S, Result.get(), T, Value, CCE,
6198
- RequireInt, PreNarrowingValue);
6142
+ return S. EvaluateConvertedConstantExpression(Result.get(), T, Value, CCE,
6143
+ RequireInt, PreNarrowingValue);
6199
6144
}
6200
6145
6201
6146
ExprResult Sema::BuildConvertedConstantExpression(Expr *From, QualType T,
@@ -6226,14 +6171,61 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr *From, QualType T,
6226
6171
return R;
6227
6172
}
6228
6173
6229
- ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
6230
- APValue &Value,
6231
- Sema::CCEKind CCE,
6232
- bool RequireInt) {
6174
+ /// EvaluateConvertedConstantExpression - Evaluate an Expression
6175
+ /// That is a converted constant expression
6176
+ /// (which was built with BuildConvertedConstantExpression)
6177
+ ExprResult
6178
+ Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value,
6179
+ Sema::CCEKind CCE, bool RequireInt,
6180
+ const APValue &PreNarrowingValue) {
6233
6181
6234
- APValue PreNarrowingValue;
6235
- return ::EvaluateConvertedConstantExpression(*this, E, T, Value, CCE,
6236
- RequireInt, PreNarrowingValue);
6182
+ ExprResult Result = E;
6183
+ // Check the expression is a constant expression.
6184
+ SmallVector<PartialDiagnosticAt, 8> Notes;
6185
+ Expr::EvalResult Eval;
6186
+ Eval.Diag = &Notes;
6187
+
6188
+ ConstantExprKind Kind;
6189
+ if (CCE == Sema::CCEK_TemplateArg && T->isRecordType())
6190
+ Kind = ConstantExprKind::ClassTemplateArgument;
6191
+ else if (CCE == Sema::CCEK_TemplateArg)
6192
+ Kind = ConstantExprKind::NonClassTemplateArgument;
6193
+ else
6194
+ Kind = ConstantExprKind::Normal;
6195
+
6196
+ if (!E->EvaluateAsConstantExpr(Eval, Context, Kind) ||
6197
+ (RequireInt && !Eval.Val.isInt())) {
6198
+ // The expression can't be folded, so we can't keep it at this position in
6199
+ // the AST.
6200
+ Result = ExprError();
6201
+ } else {
6202
+ Value = Eval.Val;
6203
+
6204
+ if (Notes.empty()) {
6205
+ // It's a constant expression.
6206
+ Expr *E = ConstantExpr::Create(Context, Result.get(), Value);
6207
+ if (!PreNarrowingValue.isAbsent())
6208
+ Value = std::move(PreNarrowingValue);
6209
+ return E;
6210
+ }
6211
+ }
6212
+
6213
+ // It's not a constant expression. Produce an appropriate diagnostic.
6214
+ if (Notes.size() == 1 &&
6215
+ Notes[0].second.getDiagID() == diag::note_invalid_subexpr_in_const_expr) {
6216
+ Diag(Notes[0].first, diag::err_expr_not_cce) << CCE;
6217
+ } else if (!Notes.empty() && Notes[0].second.getDiagID() ==
6218
+ diag::note_constexpr_invalid_template_arg) {
6219
+ Notes[0].second.setDiagID(diag::err_constexpr_invalid_template_arg);
6220
+ for (unsigned I = 0; I < Notes.size(); ++I)
6221
+ Diag(Notes[I].first, Notes[I].second);
6222
+ } else {
6223
+ Diag(E->getBeginLoc(), diag::err_expr_not_cce)
6224
+ << CCE << E->getSourceRange();
6225
+ for (unsigned I = 0; I < Notes.size(); ++I)
6226
+ Diag(Notes[I].first, Notes[I].second);
6227
+ }
6228
+ return ExprError();
6237
6229
}
6238
6230
6239
6231
/// dropPointerConversions - If the given standard conversion sequence
0 commit comments