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

--- Comment #3 from Valentin Tolmer <valentin at tolmer dot fr> ---
Digging a little bit into it, there is definitely a bug that was in 14.1 only
(and got fixed in 14.2):

struct S {
  S() = default;
  S(const S&) = delete;
};

int main() {
  S source;
  S& source2 = source;
  // Fails only in 14.1
  [](auto& key) -> S& {
    return [&] -> decltype(auto) { return key; }();
  }(source);
  [&] -> decltype(auto) { return source2; }();
  // Fails on clang++, gcc 14.1 and 14.2
  [&]() -> S& {
    return [&] -> decltype(auto) { return source; }();
  }();
  [&] -> decltype(auto) { return source; }();
}

The first 2 lambdas should clearly deduce S& for the decltype(auto), but don't
in 14.1.

Patrick, I don't think the note you linked applies here: it's not within the
compounds statement of a lambda, and it doesn't refer to a capture by value.

I think the relevant part is
"An id-expression within the compound-statement of a lambda-expression that is
an odr-use of a reference captured by reference refers to the entity to which
the captured reference is bound and not to the captured reference." which would
mean that it gets resolved to decltype(source) and thus S.

Reply via email to