[PATCH] D103789: [clangd] Type hints for C++14 return type deduction
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 14 00:13:21 PDT 2021
nridge added inline comments.
================
Comment at: clang-tools-extra/clangd/InlayHints.cpp:79
+ if (!Deduced.isNull()) {
+ SourceRange R = D->getReturnTypeSourceRange();
+ // For operator auto(), have to get location of `auto` a different way.
----------------
sammccall wrote:
> nit: bool TrailingReturnType = D->getReturnTypeSourceRange().isValid()?
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.
================
Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:505
+ )cpp",
+ ExpectedHint{": int", "ret1a"}, ExpectedHint{": int", "ret1b"},
+ ExpectedHint{": int &", "ret2"}, ExpectedHint{": int", "retConv"});
----------------
sammccall wrote:
> 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)
I like this suggestion, thanks!
I agree it's nice if the hint is in a place where it would have been valid syntax.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103789/new/
https://reviews.llvm.org/D103789
More information about the cfe-commits
mailing list