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

readability-else-after-return bug when a variable is defined in the condition #39738

Closed
llvmbot opened this issue Jan 21, 2019 · 2 comments
Closed
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 21, 2019

Bugzilla Link 40392
Resolution FIXED
Resolved on Jan 21, 2019 08:28
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @JonasToth

Extended Description

readability-else-after-return triggers for this pattern:
if (int x = ...) {
...
return 0;
} else {
// Do something with x
}

Removing the else clause would trigger a build error as x is no longer in scope

(translating a bug report from a user)

@JonasToth
Copy link
Member

This should in principle apply to C++17 if (auto Foo = bar(); Foo.method()), right?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jan 21, 2019

In this particular report the user was interested in C++11 only. But in principle - yes. I've submitted a patch to address this issue (r351751). Didn't check it for C++17 though.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

2 participants