Bug 86697 - decltype for lambda capture gives wrong type
Summary: decltype for lambda capture gives wrong type
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, rejects-valid, wrong-code
: 110752 (view as bug list)
Depends on:
Blocks: decltype lambdas
  Show dependency treegraph
 
Reported: 2018-07-27 09:13 UTC by Antony Polukhin
Modified: 2023-12-08 20:42 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-12-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antony Polukhin 2018-07-27 09:13:44 UTC
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.
Comment 1 Jonathan Wakely 2018-07-27 12:25:26 UTC
I thought we already had a bug report for this, but I don't see it linked to the PR 54367 meta-bug.
Comment 2 Andrew Pinski 2021-12-11 05:24:59 UTC
Confirmed.
Comment 3 Patrick Palka 2023-11-10 16:12:08 UTC
*** Bug 110752 has been marked as a duplicate of this bug. ***