llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.52k stars 11.79k forks source link

[clang] conversion operator to builtin _Complex not constexpr #108750

Open willwray opened 1 month ago

willwray commented 1 month ago

This arose in a generic context:

struct zero
{
  template <typename T>
  constexpr operator T() const {return {};}
};

constexpr _Complex float z0{zero{}};

error: constexpr variable 'z0' must be initialized by a constant expression

This compiler explorer snippet reduces it to a non-template example https://godbolt.org/z/YPe63E4Gf

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-frontend

Author: Will Wray (willwray)

This arose in a generic context: ```c++ struct zero { template <typename T> constexpr operator T() const {return {};} }; constexpr _Complex float z0{zero{}}; ``` `error: constexpr variable 'z0' must be initialized by a constant expression` This compiler explorer snippet reduces it to a non-template example https://godbolt.org/z/YPe63E4Gf