public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95412] New: Constexpr variables captured in templated lambdas
@ 2020-05-29 11:29 maurimo at fb dot com
  2021-08-28 22:52 ` [Bug c++/95412] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: maurimo at fb dot com @ 2020-05-29 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95412
           Summary: Constexpr variables captured in templated lambdas
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maurimo at fb dot com
  Target Milestone: ---

I am getting (9.0.1 and 10.0.1, exact versions at the end) a curious issue with
constexpr variable captured in a templated lambda, here is a concise test case:

template<typename F>
void runLambda(F&& f) {
  f.template operator()<3>();
  f.template operator()<7>();
}

int main(int argc, char* argv[]) {

  int retv = 0;
  constexpr bool q = false;

  runLambda([&]<int j>(){ // capturing with [&, q] always works
    constexpr bool z = j != 8;
    /*if constexpr(q) // <- this equivalent formulation works! ¯\_(ツ)_/¯
      if constexpr(z)
        retv += i*j;*/
    if constexpr(q && z)
      retv += j;
  });

  return retv;
}

Error (that should not happen):
test.cpp: In lambda function:
test.cpp:18:24: error: lambda capture of ‘q’ is not a constant expression
   18 |     if constexpr(q && z)
      |

Compiled with:
  g++-latest -std=c++2a simple_example/test.cpp -o test

Tried with both gcc 9.0.1:
Using built-in specs.
COLLECT_GCC=g++-9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9-20190428-1ubuntu1~18.04.york0'
--with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 9.0.1 20190428 (prerelease) [gcc-9-branch revision 270630] (Ubuntu
9-20190428-1ubuntu1~18.04.york0)

and gcc 10.0.1:
Using built-in specs.
COLLECT_GCC=g++-latest
COLLECT_LTO_WRAPPER=/opt/gcc-latest/libexec/gcc/x86_64-pc-linux-gnu/10.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-latest --enable-languages=c,c++
--enable-libstdcxx-debug --disable-bootstrap --disable-multilib
--disable-libvtv --with-system-zlib --without-isl --enable-multiarch
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200412 (experimental) (GCC)

on an Ubuntu 18.04 (x86-64).

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/95412] Constexpr variables captured in templated lambdas
  2020-05-29 11:29 [Bug c++/95412] New: Constexpr variables captured in templated lambdas maurimo at fb dot com
@ 2021-08-28 22:52 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-28 22:52 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=90212
         Resolution|---                         |FIXED
   Target Milestone|---                         |9.4
           Keywords|                            |rejects-valid

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 9.4.0, 10.2.0 and 11+ by the patch which fixes PR 90212.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-28 22:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 11:29 [Bug c++/95412] New: Constexpr variables captured in templated lambdas maurimo at fb dot com
2021-08-28 22:52 ` [Bug c++/95412] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).