[all-commits] [llvm/llvm-project] a7a634: [LLVM][Casting.h] Fix dyn_cast for std::unique_ptr.

Aleksandr Bezzubikov via All-commits all-commits at lists.llvm.org
Sun Aug 13 18:05:18 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a7a634aa2b5c815d18defc32fb837e079d96d1fc
      https://github.com/llvm/llvm-project/commit/a7a634aa2b5c815d18defc32fb837e079d96d1fc
  Author: Aleksandr Bezzubikov <zuban32s at gmail.com>
  Date:   2023-08-13 (Sun, 13 Aug 2023)

  Changed paths:
    M llvm/include/llvm/Support/Casting.h
    M llvm/unittests/Support/Casting.cpp

  Log Message:
  -----------
  [LLVM][Casting.h] Fix dyn_cast for std::unique_ptr.

Unlike isa<> and cast<>, current implementation of dyn_cast<> fails
to process a std::unique_ptr to a class supporting LLVM RTTI:

// A and B support LLVM RTTI
class A {...}
class B: public A {...}

void foo() {
...
  auto V = std::make_unique<A>();
  auto VB = dyn_cast<B>(std::move(V));
  if (VB)
    ...
...
}

Reviewed By: lattner, bzcheeseman

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




More information about the All-commits mailing list