Skip to content

Commit

Permalink
[clang][Diagnostics] Provide source range to invalid casts in const expr
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D153241
  • Loading branch information
tbaederr committed Jul 28, 2023
1 parent d5f496a commit 81fb216
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13773,7 +13773,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {

case CK_PointerToIntegral: {
CCEDiag(E, diag::note_constexpr_invalid_cast)
<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();

LValue LV;
if (!EvaluatePointer(SubExpr, LV, Info))
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ bool CheckPotentialReinterpretCast(InterpState &S, CodePtr OpPC,

const SourceInfo &E = S.Current->getSource(OpPC);
S.CCEDiag(E, diag::note_constexpr_invalid_cast)
<< 2 << S.getLangOpts().CPlusPlus;
<< 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions clang/test/Misc/constexpr-source-ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ constexpr int f() {
}

// CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}


constexpr int I = 12;
constexpr const int *P = &I;
constexpr long L = (long)P;
// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}

0 comments on commit 81fb216

Please sign in to comment.