Skip to content

Commit d8a5c79

Browse files
HoBoIswhisperity
authored andcommitted
[clang][Sema] Correct end for the CastOperation.OpRange (#69480)
Set the correct end for the CastOperation.OpRange in CXXFunctionalCastExpr. Now it is the closing bracket's location instead of the parameter's location. This can lead to better highlight in the diagnostics. Similar to #66853 Before: 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: 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*/); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Reviewed By: AaronBallman, tbaederr GitHub PR: #69480
1 parent b901aca commit d8a5c79

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,25 @@ Improvements to Clang's diagnostics
379379
can sometimes lead to worse ordering.
380380

381381

382+
- When describing a warning/error in a function-style type conversion Clang underlines only until
383+
the end of the expression we convert from. Now Clang underlines until the closing parenthesis.
384+
385+
Before:
386+
387+
.. code-block:: text
388+
389+
warning: cast from 'long (*)(const int &)' to 'decltype(fun_ptr)' (aka 'long (*)(int &)') converts to incompatible function type [-Wcast-function-type-strict]
390+
24 | return decltype(fun_ptr)( f_ptr /*comment*/);
391+
| ^~~~~~~~~~~~~~~~~~~~~~~~
392+
393+
After:
394+
395+
.. code-block:: text
396+
397+
warning: cast from 'long (*)(const int &)' to 'decltype(fun_ptr)' (aka 'long (*)(int &)') converts to incompatible function type [-Wcast-function-type-strict]
398+
24 | return decltype(fun_ptr)( f_ptr /*comment*/);
399+
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
400+
382401
Bug Fixes in This Version
383402
-------------------------
384403
- Fixed an issue where a class template specialization whose declaration is

clang/lib/Sema/SemaCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo,
33623362
assert(LPLoc.isValid() && "List-initialization shouldn't get here.");
33633363
CastOperation Op(*this, Type, CastExpr);
33643364
Op.DestRange = CastTypeInfo->getTypeLoc().getSourceRange();
3365-
Op.OpRange = SourceRange(Op.DestRange.getBegin(), CastExpr->getEndLoc());
3365+
Op.OpRange = SourceRange(Op.DestRange.getBegin(), RPLoc);
33663366

33673367
Op.CheckCXXCStyleCast(/*FunctionalCast=*/true, /*ListInit=*/false);
33683368
if (Op.SrcExpr.isInvalid())
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
1+
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info -Wcast-function-type-strict %s 2>&1 | FileCheck %s
22

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

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

0 commit comments

Comments
 (0)