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

            Bug ID: 66735
           Summary: [C++14] lambda init-capture fails for const references
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fynjycfdby at gmail dot com
  Target Milestone: ---

This code fails to compile:

int main() {
    int x = 0;
    auto l = [&rx = static_cast<const int&>(x)]() {};
}


The error message is:

test.cpp:3:14: error: binding 'const int' to reference of type 'int&' discards
qualifiers
     auto l = [&rx = static_cast<const int&>(x)]() {


But according to [expr.prim.lambda]/11 rx should be captured as auto &rx =
static_cast<const int&>(x), that is as const int&.

Tested on MacPorts g++-mp-5:

$ g++-mp-5 -v
Using built-in specs.
COLLECT_GCC=g++-mp-5
...
gcc version 5.1.0 (MacPorts gcc5 5.1.0_1)

Reply via email to