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-const-return-type identifies the wrong const token that qualifies the return type #43671

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

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 17, 2019

Bugzilla Link 44326
Resolution FIXED
Resolved on Jan 04, 2020 14:45
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @JonasToth

Extended Description

For the following code located in const-ret-type.cpp:

const int* const volatile foo() {}

The following invocation of clang-tidy produces the following output:

$ clang-tidy -checks=-*,readability-const-return-type const-ret-type.cpp
2 warnings generated.
const-ret-type.cpp:1:1: warning: return type 'const int const volatile' is 'const'-qualified at the top level, ...
const int
const volatile foo() {}
^~~~~~
Suppressed 1 warnings (1 with check filters).

While the expected diagnostic should be:

const int* const volatile foo() {}
^~~~~~

The readability-const-return-type checker incorrectly flags the first const token, but it's actually the other const token that precedes volatile that qualifies the return type. Applying the suggested fixit can result in a miscompilation. The culprit is in the implementation of the utils::lexer::getConstQualifyingToken function. I have a patch ready and I plan to submit it for review shortly.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 19, 2019

A fix is up for a review: https://reviews.llvm.org/D71666

@JonasToth
Copy link
Member

fixede with https://reviews.llvm.org/rGf58f39137c6e5a324ef684b1d72bddae244aa94d

Thank you for the patch!

@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