Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Correct end for the CastOperation.OpRange #69480

Closed
wants to merge 1 commit into from

Conversation

HoBoIs
Copy link
Contributor

@HoBoIs HoBoIs commented Oct 18, 2023

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
Example:
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*/);
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 18, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 18, 2023

@llvm/pr-subscribers-clang

Author: Botond István Horváth (HoBoIs)

Changes

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
Example:
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*/);
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Full diff: https://github.com/llvm/llvm-project/pull/69480.diff

1 Files Affected:

  • (modified) clang/lib/Sema/SemaCast.cpp (+1-1)
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 98b5879456e2175..87e6d1a2198fcea 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -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())

@tbaederr
Copy link
Contributor

The output looks good, but you should probably add a test in clang/test/Misc/misc-source-ranges.cpp.

@whisperity whisperity changed the title Correct end for the CastOperation.OpRange [clang] Correct end for the CastOperation.OpRange Oct 19, 2023
@tbaederr
Copy link
Contributor

LGTM but let's ping @cjdb and @AaronBallman and check if they see a problem.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please add a release note about the diagnostic improvement.

clang/docs/ReleaseNotes.rst Outdated Show resolved Hide resolved
clang/test/Misc/misc-source-ranges.cpp Outdated Show resolved Hide resolved
clang/test/Misc/misc-source-ranges.cpp Outdated Show resolved Hide resolved
Set the correct end for the CastOperation.OpRange in CXXFunctionalCastExpr. Now it is the closing bracket's location instead of the parameter's location.
whisperity pushed a commit that referenced this pull request Oct 24, 2023
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
@whisperity whisperity closed this Oct 24, 2023
@HoBoIs HoBoIs deleted the HoBoIs-patch-1 branch March 25, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants