[all-commits] [llvm/llvm-project] 002981: [ADT] Support `.Default` with `nullptr` and `nullo...

Jakub Kuderski via All-commits all-commits at lists.llvm.org
Thu Oct 30 10:28:03 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0029815af7b8335054345e2f5aacf68ef9d18e81
      https://github.com/llvm/llvm-project/commit/0029815af7b8335054345e2f5aacf68ef9d18e81
  Author: Jakub Kuderski <jakub at nod-labs.com>
  Date:   2025-10-30 (Thu, 30 Oct 2025)

  Changed paths:
    M llvm/include/llvm/ADT/TypeSwitch.h
    M llvm/unittests/ADT/TypeSwitchTest.cpp

  Log Message:
  -----------
  [ADT] Support `.Default` with `nullptr` and `nullopt` values in TypeSwitch (#165724)

In the previous implementation, this would fail for cases like
`TypeSwitch<T*, std::optional<U>>` because `std::nullopt` does not match
`ResultT` exactly and the overload for callable types would be selected.

Add new overloads that support `nullptr` and `std::nullopt`. These can
be added alongside generic callables because we wouldn't want to call
any 'null' function refs anyway.

I selected the `nullptr` and `nullopt` specializations because how often
they appear in the codebase -- currently, you will see lots of code like
`.Default(std::optional<T>())` that can be simplified with this patch.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list