https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91742

--- Comment #8 from Diego Franco <di...@franco-technologies.com> ---
So to summarize, these are the main reason why I believe this should be
addressed:

- init brace works for references of any type:

std::vector<int> a {};
std::vector<int>& b {a};
assert(&a == &b); // works

int c {};
int& d {c};
assert(&c == &d); // works

- init brace works for user defined conversion reference when using static
cast:

class A { 
  operator const std::vector<int>&() const {return a_;} 
  std::vector<int> a_; 
};

A a {};
const auto& b {static_cast<const std::vector<int>&>(a)};
assert(&a == &b); // works

- init brace does not work for user defined conversion reference WITHOUT static
cast:

A a {};
const auto& b {a};
assert(&a == &b); // does not work


I think the above behavior is quite unexpected, and does not follow any logic
of other behaviors in the language. I found this unexpected behavior by running
unit tests. Also, semantic wise is correct to use user-defined-conversion
without static cast (above example).

Reply via email to