[all-commits] [llvm/llvm-project] e5e0e0: [NFC] Cleanup the overload of ASTImporter::import()

Balazs Benics via All-commits all-commits at lists.llvm.org
Thu Sep 30 02:53:42 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e5e0e00831ba093639edbd443b6e05b3118f8930
      https://github.com/llvm/llvm-project/commit/e5e0e00831ba093639edbd443b6e05b3118f8930
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-09-30 (Thu, 30 Sep 2021)

  Changed paths:
    M clang/lib/AST/ASTImporter.cpp

  Log Message:
  -----------
  [NFC] Cleanup the overload of ASTImporter::import()

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::type`s, 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.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D109269




More information about the All-commits mailing list