This is an archive of the discontinued LLVM Phabricator instance.

Better source location for -Wignored-qualifiers on trailing return types
ClosedPublic

Authored by aaronpuchert on Oct 25 2020, 6:44 PM.

Details

Summary

We collect the source location of a trailing return type in the parser,
improving the location for regular functions and providing a location
for lambdas, where previously there was none.

Fixes PR47732.

Diff Detail

Event Timeline

aaronpuchert created this revision.Oct 25 2020, 6:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2020, 6:44 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaronpuchert requested review of this revision.Oct 25 2020, 6:44 PM
aaronpuchert edited the summary of this revision. (Show Details)Oct 25 2020, 6:46 PM
aaronpuchert added inline comments.
clang/lib/Sema/SemaType.cpp
3088–3090

I'm open to always using the RParenLoc.

aaron.ballman added inline comments.Oct 27 2020, 10:00 AM
clang/lib/Sema/SemaType.cpp
3088–3090

Any reason not to track the trailing return type location on the DeclaratorChunk::FunctionTypeInfo object? That already tracks whether the return type is trailing or not as well as a bunch of other source location information.

The right paren loc isn't necessarily a good place given the grammar allows a *lot* of optional stuff between the closing paren and the trailing return type: http://eel.is/c++draft/dcl.decl#general-5

aaronpuchert marked an inline comment as done.

Collect location of a trailing return type in the parser, use that for the warning.

I resisted clang-format's urge to reflow the large parameter lists, I hope that's the right thing here.

aaronpuchert retitled this revision from Source location for -Wignored-qualifiers on lambda trailing return type to Better source location for -Wignored-qualifiers on trailing return types.Oct 27 2020, 6:38 PM
aaronpuchert edited the summary of this revision. (Show Details)
aaron.ballman accepted this revision.Oct 28 2020, 5:52 AM

LGTM aside from a question about a potential assert to add.

clang/include/clang/Sema/DeclSpec.h
1509

Should we assert(HasTrailingReturnType);?

This revision is now accepted and ready to land.Oct 28 2020, 5:52 AM
aaronpuchert marked an inline comment as done.Oct 28 2020, 7:21 AM
aaronpuchert added inline comments.
clang/include/clang/Sema/DeclSpec.h
1509

Makes sense to me. Ok if I add the assertion to this and the previous function for consistency?

aaron.ballman added inline comments.Oct 28 2020, 8:11 AM
clang/include/clang/Sema/DeclSpec.h
1509

Fine by me!

This revision was landed with ongoing or failed builds.Oct 28 2020, 3:33 PM
This revision was automatically updated to reflect the committed changes.
aaronpuchert marked an inline comment as done.
aaronpuchert marked an inline comment as done.Oct 28 2020, 3:35 PM

Added the assertions in a follow-up change rGebfc427bbe08f0c36af9721d5a4e6d3ffe2e4bf5.