This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Type hints for C++14 return type deduction
ClosedPublic

Authored by nridge on Jun 6 2021, 11:54 PM.

Diff Detail

Event Timeline

nridge created this revision.Jun 6 2021, 11:54 PM
nridge requested review of this revision.Jun 6 2021, 11:54 PM
sammccall accepted this revision.Jun 7 2021, 6:04 AM
sammccall added inline comments.
clang-tools-extra/clangd/InlayHints.cpp
79

nit: bool TrailingReturnType = D->getReturnTypeSourceRange().isValid()?

clang-tools-extra/clangd/unittests/InlayHintTests.cpp
505

This reads as "auto[: int] f1(int x);", which doesn't look much like familiar syntax, C++ or otherwise.

I guess we could try auto f1(int x)[-> int];?

(From playing with these in vscode, I'm not sure I find the punctuation very useful)

This revision is now accepted and ready to land.Jun 7 2021, 6:04 AM
nridge added inline comments.Jun 14 2021, 12:13 AM
clang-tools-extra/clangd/InlayHints.cpp
79

Sorry, I don't really understand this comment.

If you're thinking about the test case where a trailing return type is present and we avoid producing a hint in that case (f3 in TypeHints.ReturnTypeDeduction), that happens because getContainedAutoType() returns null, so we don't get into this block at all.

clang-tools-extra/clangd/unittests/InlayHintTests.cpp
505

I like this suggestion, thanks!

I agree it's nice if the hint is in a place where it would have been valid syntax.

nridge updated this revision to Diff 351788.Jun 14 2021, 12:14 AM

Put hint in trailing return type position

This revision was automatically updated to reflect the committed changes.