readability-const-return-type identifies the wrong const
token that qualifies the return type
#43671
Labels
const
token that qualifies the return type
#43671
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 otherconst
token that precedesvolatile
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.The text was updated successfully, but these errors were encountered: