This is an archive of the discontinued LLVM Phabricator instance.

[clang] Build UsingType for elaborated type specifiers.
ClosedPublic

Authored by hokein on Jan 9 2023, 6:46 AM.

Details

Summary

To support building UsingType for elaborated type specifiers:

namespace ns { class Foo {}; }

using ns::Foo;

// The TypeLoc of `Foo` below should be a ElaboratedTypeLoc with an
inner UsingTypeLoc rather than the underlying `CXXRecordTypeLoc`
class Foo foo;

It seems to work, and improves some diagnostics.

Diff Detail

Event Timeline

hokein created this revision.Jan 9 2023, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 6:46 AM
Herald added a subscriber: kadircet. · View Herald Transcript
hokein requested review of this revision.Jan 9 2023, 6:46 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 9 2023, 6:46 AM

though this is a hack implementation, the result seems promising to me, so I post it for initial thoughts.

clang/include/clang/Sema/Sema.h
3306–3307

This is the key place where it returns the underlying decl.

Alternatively, we could return the UsingDecl as the result (there are only 4 places using it, might be possible to check/verify/adjust all caller place, I feel a bit scary about it, as the name indicates, caller might assume the return Decl is a TagDecl, e.g. the case)

I'll bite, why do you say it's hacky?
Looks OK to me, by clang standards :-)

clang/include/clang/Sema/DeclSpec.h
516

elsewhere we call this the found decl, seems worth sticking with the terminology unless there's a distinction I'm missing.

(I'd also add a comment here, even though it doesn't seem to be local style, sigh)

clang/include/clang/Sema/Sema.h
3306–3307

Yeah, given the name I think returning the TagDecl makes sense.
(It looks like it should always return TagDecl, though it's hard to tell - if so then changing the static type to TagDecl* seems like it would help)

I think the extra out-param is fine, except given that there are few callsites, I'd prefer a mandatory FoundUsingShadow*& and explicitly ignoring it where appropriate - seems less cryptic and makes discarding sugar more obvious.

3307

nit: needs clang-format for pointer-alignment here and elsewhere

hokein updated this revision to Diff 488403.Jan 11 2023, 3:42 PM
hokein marked 2 inline comments as done.

address comments.

hokein retitled this revision from [clang][wip] Build UsingType for elaborated type specifiers. to [clang] Build UsingType for elaborated type specifiers..Jan 12 2023, 1:46 AM
hokein edited the summary of this revision. (Show Details)
hokein added inline comments.
clang/lib/Parse/ParseDeclCXX.cpp
2136
sammccall accepted this revision.Jan 12 2023, 2:46 AM
sammccall added inline comments.
clang/include/clang/Sema/DeclSpec.h
510

urgh, this function is now misnamed, because the decl we're returning isn't the representation.
But changing it seems like a lot of unneccesary churn and confusion.
So no action required, I'm just making a face :-S

This revision is now accepted and ready to land.Jan 12 2023, 2:46 AM
This revision was landed with ongoing or failed builds.Jan 19 2023, 5:21 AM
This revision was automatically updated to reflect the committed changes.