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

Missing diagnostics "warning: type qualifiers ignored on function return type" #55450

Open
pmor13 opened this issue May 13, 2022 · 3 comments
Open
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@pmor13
Copy link

pmor13 commented May 13, 2022

typedef const int T;
T f(void);
$ clang -c -std=c11 -pedantic -Wall -Wextra
<nothing>
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels May 13, 2022
@shafik
Copy link
Collaborator

shafik commented May 13, 2022

For C++ this will also miss this case:

typedef const int T;
auto f(void) -> T;

@shafik
Copy link
Collaborator

shafik commented May 14, 2022

This is failing in diagnoseRedundantReturnTypeQualifiers(...) the step before in GetFullTypeForDeclarator(...) we are using getCVRQualifiers() to detect if there are cv-qualifiers, this looks through type sugar.

Inside diagnoseRedundantReturnTypeQualifiers(...) for the trailing return type case we use getLocalCVRQualifiers() which does not look through type sugar.

For the case reported by the OP we are using D.getDeclSpec().getTypeQualifiers() and the DeclSpec does look through the type sugar.

The problem is not simply looking through the type sugar, it is also getting a quality diagnostic. For example for the trailing return type case if we used RetTy.getCVRQualifiers() instead we would obtain a diagnostic like this:

warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
auto f2(void) -> T;
                 ^

which would not be too helpful.

@AaronBallman
Copy link
Collaborator

This issue is related to #39494

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

4 participants