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

            Bug ID: 80642
           Summary: lambdas made constexpr in cases where they don't
                    satisfy the requirements for it
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mathias at gaunard dot com
  Target Milestone: ---

Since C++17, lambdas are automatically constexpr whenever they can.
It seems however that GCC 7.1 tries to make lambdas constexpr in cases where it
actually can not.

Testcase, built with -std=c++1z

#include <array>

int main()
{
    [](auto&& i)
    {
        if(i)
        {
            std::array<char, 4> array;
            return i + array.size();
        }
        return i;
    }(std::size_t(0));
}

Expected behaviour: everything compiles fine

What I get instead:

test.cpp: In instantiation of ‘main()::<lambda(auto:1&&)> [with auto:1 = long
unsigned int]’:
test.cpp:13:21:   required from here
test.cpp:9:33: error: uninitialized variable ‘array’ in ‘constexpr’ function
             std::array<char, 4> array;
                                 ^~~~~
In file included from test.cpp:1:0:
/usr/local/gcc-7.1.0/include/c++/7.1.0/array:94:12: note: ‘struct
std::array<char, 4>’ has no user-provided default constructor
     struct array
            ^~~~~
/usr/local/gcc-7.1.0/include/c++/7.1.0/array:110:56: note: and the
implicitly-defined constructor does not initialize ‘char std::array<char,
4>::_M_elems [4]’
       typename _AT_Type::_Type                         _M_elems;
                                                        ^~~~~~~~

Reply via email to