[Bug c++/89643] New: constexpr capture not working inside expression

rcc.dark at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Mar 9 22:57:00 GMT 2019


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

            Bug ID: 89643
           Summary: constexpr capture not working inside expression
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rcc.dark at gmail dot com
  Target Milestone: ---

Created attachment 45928
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45928&action=edit
Source code that triggers the bug

Hi all, this code does not compile ("closure not a constant expression") in GCC
8.3 and Trunk (from https://godbolt.org/).

---

#include <array>

constexpr int f(const int& n, const int& m) {
   return n + m;
}

int main( ) {
   constexpr int N = 1;
   auto lambda = [&] {
      std::array<int, f(N, 1)> arr;
   };
}

---

The code compiles in ICC and Clang.
How to make this compile in GCC:
 - Make f take parameters by value
  OR
 - Declare N inside the lambda.
  OR
 - Remove [&] capture.

PS. Sorry if duplicate bug, couldn't find earlier reports.


More information about the Gcc-bugs mailing list