Skip to content

[clang-tidy] false negative for misc-const-correctness in function-try-block #99860

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

Closed
schenker opened this issue Jul 22, 2024 · 1 comment · Fixed by #99925
Closed

[clang-tidy] false negative for misc-const-correctness in function-try-block #99860

schenker opened this issue Jul 22, 2024 · 1 comment · Fixed by #99925

Comments

@schenker
Copy link
Contributor

schenker commented Jul 22, 2024

The check misc-const-correctness of clang-tidy 19.0.0git (20d3815) does not work as expected for function-try-blocks.

For the following function the warning warning variable 'i' of type 'int' can be declared 'const' [misc-const-correctness] is generated.

int tp() {
  try {
    int i = 0;
    return i;
  } catch (...) {
    return 0;
  }
}

When the outer curly braces are ommited, the check does not report a warning.

int fn() try {
  int i = 0;
  return i;
} catch (...) {
  return 0;
}
@PiotrZSL
Copy link
Member

PiotrZSL commented Jul 22, 2024

This is because of "hasBody(compoundStmt", shouldn't be hard to fix, changing this into "hasBody(stmt" should do a trick.

PiotrZSL pushed a commit that referenced this issue Jul 23, 2024
…cks (#99925)

Make the clang-tidy check misc-const-correctness work with
function-try-blocks.

Fixes #99860.
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
…cks (#99925)

Make the clang-tidy check misc-const-correctness work with
function-try-blocks.

Fixes #99860.
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
…cks (#99925)

Summary:
Make the clang-tidy check misc-const-correctness work with
function-try-blocks.

Fixes #99860.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251131
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants