sourceLocToPosition(SM, Spelled->back().endLocation())};
}
+ static bool shouldPrintCanonicalType(QualType QT) {
+ // The sugared type is more useful in some cases, and the canonical
+ // type in other cases. For now, prefer the sugared type unless
+ // we are printing `decltype(expr)`. This could be refined further
+ // (see https://github.com/clangd/clangd/issues/1298).
+ if (QT->isDecltypeType())
+ return true;
+ if (const AutoType *AT = QT->getContainedAutoType())
+ if (AT->getDeducedType()->isDecltypeType())
+ return true;
+ return false;
+ }
+
void addTypeHint(SourceRange R, QualType T, llvm::StringRef Prefix) {
+ TypeHintPolicy.PrintCanonicalTypes = shouldPrintCanonicalType(T);
addTypeHint(R, T, Prefix, TypeHintPolicy);
}
TEST(TypeHints, Decltype) {
assertTypeHints(R"cpp(
$a[[decltype(0)]] a;
- // FIXME: will be nice to show `: int` instead
$b[[decltype(a)]] b;
const $c[[decltype(0)]] &c = b;
template <class, class> struct Foo;
using G = Foo<$g[[decltype(0)]], float>;
+
+ auto $h[[h]] = $i[[decltype(0)]]{};
)cpp",
- ExpectedHint{": int", "a"},
- ExpectedHint{": decltype(0)", "b"},
+ ExpectedHint{": int", "a"}, ExpectedHint{": int", "b"},
ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
- ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"});
+ ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"},
+ ExpectedHint{": int", "h"}, ExpectedHint{": int", "i"});
}
TEST(DesignatorHints, Basic) {