Skip to content

Commit 9e08ddf

Browse files
committed
refactor select in note_constexpr_invalid_cast
1 parent dfc517b commit 9e08ddf

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ let Component = "AST" in {
1111
// Constant expression diagnostics. These (and their users) belong in Sema.
1212
def note_expr_divide_by_zero : Note<"division by zero">;
1313
def note_constexpr_invalid_cast : Note<
14-
"%select{reinterpret_cast|dynamic_cast|%select{this conversion|cast that"
15-
" performs the conversions of a reinterpret_cast}1|cast from %1}0"
14+
"%enum_select<CastKind>{%Reinterpret{reinterpret_cast}|%Dynamic{dynamic_cast}|"
15+
"%ThisCastOrReinterpret{%select{this conversion|cast that performs the conversions "
16+
"of a reinterpret_cast}1}|%CastFrom{cast from %1}}0"
1617
" is not allowed in a constant expression"
1718
"%select{| in C++ standards before C++20||}0">;
1819
def note_constexpr_invalid_void_star_cast : Note<

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,12 +2366,12 @@ static inline bool PtrPtrCast(InterpState &S, CodePtr OpPC, bool SrcIsVoidPtr) {
23662366
} else if (!S.getLangOpts().CPlusPlus26) {
23672367
const SourceInfo &E = S.Current->getSource(OpPC);
23682368
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2369-
<< 3 << "'void *'" << S.Current->getRange(OpPC);
2369+
<< diag::CastKind::CastFrom << "'void *'" << S.Current->getRange(OpPC);
23702370
}
23712371
} else {
23722372
const SourceInfo &E = S.Current->getSource(OpPC);
23732373
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
2374-
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
2374+
<< diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
23752375
}
23762376

23772377
return true;
@@ -2736,7 +2736,7 @@ inline bool GetIntPtr(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
27362736

27372737
if (Desc)
27382738
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast)
2739-
<< 2 << S.getLangOpts().CPlusPlus;
2739+
<< diag::CastKind::ThisCastOrReinterpret << S.getLangOpts().CPlusPlus;
27402740

27412741
S.Stk.push<Pointer>(static_cast<uint64_t>(IntVal), Desc);
27422742
return true;

clang/lib/AST/ExprConstant.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8103,12 +8103,12 @@ class ExprEvaluatorBase
81038103
}
81048104

81058105
bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) {
8106-
CCEDiag(E, diag::note_constexpr_invalid_cast) << 0;
8106+
CCEDiag(E, diag::note_constexpr_invalid_cast) << diag::CastKind::Reinterpret;
81078107
return static_cast<Derived*>(this)->VisitCastExpr(E);
81088108
}
81098109
bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) {
81108110
if (!Info.Ctx.getLangOpts().CPlusPlus20)
8111-
CCEDiag(E, diag::note_constexpr_invalid_cast) << 1;
8111+
CCEDiag(E, diag::note_constexpr_invalid_cast) << diag::CastKind::Dynamic;
81128112
return static_cast<Derived*>(this)->VisitCastExpr(E);
81138113
}
81148114
bool VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *E) {
@@ -8833,7 +8833,7 @@ class LValueExprEvaluator
88338833

88348834
case CK_LValueBitCast:
88358835
this->CCEDiag(E, diag::note_constexpr_invalid_cast)
8836-
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
8836+
<< diag::CastKind::ThisCastOrReinterpret << Info.Ctx.getLangOpts().CPlusPlus;
88378837
if (!Visit(E->getSubExpr()))
88388838
return false;
88398839
Result.Designator.setInvalid();
@@ -9670,10 +9670,10 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
96709670
<< E->getType()->getPointeeType();
96719671
else
96729672
CCEDiag(E, diag::note_constexpr_invalid_cast)
9673-
<< 3 << SubExpr->getType();
9673+
<< diag::CastKind::CastFrom << SubExpr->getType();
96749674
} else
96759675
CCEDiag(E, diag::note_constexpr_invalid_cast)
9676-
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
9676+
<< diag::CastKind::ThisCastOrReinterpret << Info.Ctx.getLangOpts().CPlusPlus;
96779677
Result.Designator.setInvalid();
96789678
}
96799679
}
@@ -9712,7 +9712,7 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
97129712

97139713
case CK_IntegralToPointer: {
97149714
CCEDiag(E, diag::note_constexpr_invalid_cast)
9715-
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
9715+
<< diag::CastKind::ThisCastOrReinterpret << Info.Ctx.getLangOpts().CPlusPlus;
97169716

97179717
APValue Value;
97189718
if (!EvaluateIntegerOrLValue(SubExpr, Value, Info))
@@ -11177,7 +11177,7 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) {
1117711177
// Give up if the input isn't an int, float, or vector. For example, we
1117811178
// reject "(v4i16)(intptr_t)&a".
1117911179
Info.FFDiag(E, diag::note_constexpr_invalid_cast)
11180-
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
11180+
<< diag::CastKind::ThisCastOrReinterpret << Info.Ctx.getLangOpts().CPlusPlus;
1118111181
return false;
1118211182
}
1118311183

@@ -15196,7 +15196,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1519615196

1519715197
case CK_PointerToIntegral: {
1519815198
CCEDiag(E, diag::note_constexpr_invalid_cast)
15199-
<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
15199+
<< diag::CastKind::ThisCastOrReinterpret << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
1520015200

1520115201
LValue LV;
1520215202
if (!EvaluatePointer(SubExpr, LV, Info))

0 commit comments

Comments
 (0)