This patch aims to address the comment of a previous review:
https://reviews.llvm.org/D109237#inline-1040678
The original problem was the following:
`T` is substituted by `clang::Type`
Expected<T *> import(T *From) { auto ToOrErr = Importer.Import(From); // ^^^^^^^^^^^^^^^^^^^^^ if (!ToOrErr) return ToOrErr.takeError(); return cast_or_null<T>(*ToOrErr); // ^^^^^^^^^^^^^^^^^^^^^^^^^ }
Importer.Import() operates on const Type *, thus returns const Type *.
Later, at the return statement, we will try to construct an Expected<Type*>
from a const Type *, which failed with a miserable error message.
In all other cases importer.Import() results in a non-const version,
so everything works out just fine, but for clang::types, we should
really return a const version.
So, in case of T is a subclass of clang::Type, it will return a
Exprected<const T*> instead.
clang-format: please reformat the code