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

            Bug ID: 105291
           Summary: include/c++/12.0.1/debug/safe_unordered_container.h:71
                    :28: error: captured variable '__local_end' cannot
                    appear here
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

Since
<https://github.com/llvm/llvm-project/commit/04000c2f928a7adc32138a664d167f01b642bef3>
"[clang] Implement Change scope of lambda trailing-return-type", Clang 15 trunk
implements
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2036r3.html> "Change
scope of lambda trailing-return-type" as a DR (in line with
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/n4902.html> "N4902
Editors’ Report – Programming Languages – C++"; so enabled with all -std=
versions).

That stated to cause

> $ cat test.cc 
> #define _GLIBCXX_DEBUG
> #include <unordered_map>

> $ clang++ -fsyntax-only test.cc
> In file included from test.cc:2:
> In file included from 
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/unordered_map:52:
> In file included from 
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/unordered_map:49:
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:71:28:
>  error: captured variable '__local_end' cannot appear here
>                 [__local_end](__decltype(__local_end) __it)
>                                          ^
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:71:4:
>  note: variable '__local_end' is explicitly captured here
>                 [__local_end](__decltype(__local_end) __it)
>                  ^
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:69:2:
>  note: '__local_end' declared here
>         auto __local_end = _M_cont()._M_base().cend(0);
>         ^
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:169:44:
>  error: captured variable '__end' cannot appear here
>         this->_M_invalidate_if([__end](__decltype(__end) __it)
>                                                   ^
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:169:26:
>  note: variable '__end' is explicitly captured here
>         this->_M_invalidate_if([__end](__decltype(__end) __it)
>                                 ^
> /usr/lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/debug/safe_unordered_container.h:168:2:
>  note: '__end' declared here
>         auto __end = _M_cont()._M_base().cend();
>         ^
> 2 errors generated.

to fail.

The relevant code in libstdc++-v3/include/debug/safe_unordered_container.h got
added with
<https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=4b763deedb282b480fe4c2b3a8ad07192393f1b1>
"2018-10-24  François Dumont  <fdum...@gcc.gnu.org>".

What made things work for me is

> diff --git a/libstdc++-v3/include/debug/safe_unordered_container.h 
> b/libstdc++-v3/include/debug/safe_unordered_container.h
> index 91be256611a..71468198573 100644
> --- a/libstdc++-v3/include/debug/safe_unordered_container.h
> +++ b/libstdc++-v3/include/debug/safe_unordered_container.h
> @@ -67,8 +67,9 @@ namespace __gnu_debug
>        _M_invalidate_locals()
>        {
>         auto __local_end = _M_cont()._M_base().cend(0);
> +       using __local_end_t = __decltype(__local_end);
>         this->_M_invalidate_local_if(
> -               [__local_end](__decltype(__local_end) __it)
> +               [__local_end](__local_end_t __it)
>                 { return __it != __local_end; });
>        }
>  
> @@ -166,7 +167,8 @@ namespace __gnu_debug
>        _M_invalidate_all()
>        {
>         auto __end = _M_cont()._M_base().cend();
> -       this->_M_invalidate_if([__end](__decltype(__end) __it)
> +       using __end_t = __decltype(__end);
> +       this->_M_invalidate_if([__end](__end_t __it)
>                                { return __it != __end; });
>         _M_invalidate_locals();
>        }

Reply via email to