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