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

            Bug ID: 86697
           Summary: decltype for lambda capture gives wrong type
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

According to the wg21.link/P0588R1 and Richard Smith's words from
https://bugs.llvm.org//show_bug.cgi?id=38325#c1 the following code should
compile:

#include <type_traits>
#include <cassert>

constexpr std::true_type  is_const(int const &)   { return {}; }
constexpr std::false_type is_const(int &)         { return {}; }

int main() {
  int x = 0;
  [y = x, x] {
    const int z = 0;
    assert(is_const(x)); // OK
    assert(is_const(y)); // OK
    assert(is_const(z)); // OK

    static_assert(decltype(is_const(x))::value, ""); // Fails
    static_assert(decltype(is_const(y))::value, "");
    static_assert(decltype(is_const(z))::value, "");

    static_assert(!std::is_const<decltype(x)>::value, "");
    static_assert(!std::is_const<decltype(y)>::value, "");  // Fails
    static_assert(std::is_const<decltype(z)>::value, "");
  } ();
}

However, two lines marked with "Fails" do not pass the asserts in -std=c++2a
mode.

Reply via email to