Skip to content

Commit

Permalink
Correct end for the CastOperation.OpRange
Browse files Browse the repository at this point in the history
Set the correct end for the CastOperation.OpRange in CXXFunctionalCastExpr. Now it is the closing bracket's location instead of the parameter's location.
  • Loading branch information
HoBoIs committed Oct 24, 2023
1 parent 5af3742 commit c065353
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
19 changes: 19 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,25 @@ Improvements to Clang's diagnostics
can sometimes lead to worse ordering.


- When describing a warning/error in a function-style type conversion Clang underlines only until
the end of the expression we convert from. Now Clang underlines until the closing parenthesis.

Before:

.. code-block:: text
warning: cast from 'long (*)(const int &)' to 'decltype(fun_ptr)' (aka 'long (*)(int &)') converts to incompatible function type [-Wcast-function-type-strict]
24 | return decltype(fun_ptr)( f_ptr /*comment*/);
| ^~~~~~~~~~~~~~~~~~~~~~~~
After:

.. code-block:: text
warning: cast from 'long (*)(const int &)' to 'decltype(fun_ptr)' (aka 'long (*)(int &)') converts to incompatible function type [-Wcast-function-type-strict]
24 | return decltype(fun_ptr)( f_ptr /*comment*/);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bug Fixes in This Version
-------------------------
- Fixed an issue where a class template specialization whose declaration is
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3362,7 +3362,7 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo,
assert(LPLoc.isValid() && "List-initialization shouldn't get here.");
CastOperation Op(*this, Type, CastExpr);
Op.DestRange = CastTypeInfo->getTypeLoc().getSourceRange();
Op.OpRange = SourceRange(Op.DestRange.getBegin(), CastExpr->getEndLoc());
Op.OpRange = SourceRange(Op.DestRange.getBegin(), RPLoc);

Op.CheckCXXCStyleCast(/*FunctionalCast=*/true, /*ListInit=*/false);
if (Op.SrcExpr.isInvalid())
Expand Down
8 changes: 7 additions & 1 deletion clang/test/Misc/misc-source-ranges.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info -Wcast-function-type-strict %s 2>&1 | FileCheck %s

struct S {
char a : 12 - 12;
};
// CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}

using fun = long(*)(int &);
fun foo(){
long (*f_ptr)(const int &);
return fun(f_ptr);
}
// CHECK: misc-source-ranges.cpp:[[@LINE-2]]:10:{[[@LINE-2]]:10-[[@LINE-2]]:20}

0 comments on commit c065353

Please sign in to comment.