public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-20 21:07 ` redi at gcc dot gnu.org
  2020-03-20 21:08 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-20 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cjdb.ns at gmail dot com

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 94241 has been marked as a duplicate of this bug. ***

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

* [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
  2020-03-20 21:07 ` [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction redi at gcc dot gnu.org
@ 2020-03-20 21:08 ` redi at gcc dot gnu.org
  2020-05-01  2:43 ` ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-20 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-03-20
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
>From PR 94241:

#include <algorithm>

int main()
{
    struct s { int m; };
    s r[] = { s{0}, s{1}, s{2}, s{3} };
    std::ranges::find_if(r, [](auto const) { return true; });
}

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

* [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
  2020-03-20 21:07 ` [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction redi at gcc dot gnu.org
  2020-03-20 21:08 ` redi at gcc dot gnu.org
@ 2020-05-01  2:43 ` ppalka at gcc dot gnu.org
  2020-05-01  2:53 ` ppalka at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-05-01  2:43 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> The following should compile, because the undefined member function is never
> odr-used, only its return type is needed.

Hmm.. don't we end up odr-using the undefined member function when checking the 

   { ranges::iter_move(__in) } -> same_as<iter_rvalue_reference_t<_In>>;

requirement of the concept __indirectly_readable_impl (as part of the concept
indirect_unary_predicate)?

In order to verify this requirement we need to determine the return type of
ranges::iter_move(__in).  But the operator() of this CPO has a decltype(auto)
return type, so determining its return type requires instantiating its body:

      struct _IMove
      {
        template<typename _Tp>
          requires __adl_imove<_Tp> || requires(_Tp& __e) { *__e; }
          constexpr _Blah<_Tp>::type
          operator()(_Tp&& __e) const
          noexcept(_S_noexcept<_Tp>())
          {
            if constexpr (__adl_imove<_Tp>)
              return iter_move(static_cast<_Tp&&>(__e));
            else if constexpr (is_reference_v<iter_reference_t<_Tp>>)
              return std::move(*__e);
            else
              return *__e;
          }
      };

And this instantiated function body (the second branch of the constexpr if)
would then odr-use this undefined member function, IIUC.

So could this be another example where defining the operator() of a CPO with a
deduced return type leads to excessive instantiation?

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

* [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-05-01  2:43 ` ppalka at gcc dot gnu.org
@ 2020-05-01  2:53 ` ppalka at gcc dot gnu.org
  2020-05-01  8:07 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-05-01  2:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Created attachment 48428
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48428&action=edit
avoid defining _IMove::operator() with a deduced return type

With this patch both of the above testcases successfully compile, which seems
to suggest that ranges::iter_move's deduced return type is indeed the problem.

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

* [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-05-01  2:53 ` ppalka at gcc dot gnu.org
@ 2020-05-01  8:07 ` redi at gcc dot gnu.org
  2020-05-01 10:35 ` [Bug libstdc++/92894] " redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-01  8:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Drat, I think you're right.

So once again, deduced return types cause problems. But this also suggests to
me that the design of std::projected is a problem, because anywhere it might
get used has to be very careful and avoid using idiomatic C++.

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2020-05-01  8:07 ` redi at gcc dot gnu.org
@ 2020-05-01 10:35 ` redi at gcc dot gnu.org
  2020-05-01 13:28 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-01 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Target Milestone|---                         |10.0
          Component|c++                         |libstdc++
             Status|NEW                         |ASSIGNED

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Mine then.

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2020-05-01 10:35 ` [Bug libstdc++/92894] " redi at gcc dot gnu.org
@ 2020-05-01 13:28 ` cvs-commit at gcc dot gnu.org
  2020-05-01 15:52 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-01 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:a5f2fb1ff1742685a91dfdf78da871fd4d3292e5

commit r11-10-ga5f2fb1ff1742685a91dfdf78da871fd4d3292e5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 1 14:27:25 2020 +0100

    libstdc++: Replace deduced return type in ranges::iter_move (PR 92894)

    The deduced return type causes the instantiation of the function body,
    which can then require the instantiation of std::projected::operator*
    which is intentionally not defined.

    This patch uses a helper trait to define the return type, so that the
    function body doesn't need to be instantiated. That helper trait can
    then also be used in other places that currently check the return type
    of ranges::iter_move (iter_rvalue_reference_t and indirectly_readable).

    2020-05-01  Jonathan Wakely  <jwakely@redhat.com>
                Patrick Palka  <ppalka@redhat.com>

            PR libstdc++/92894
            * include/bits/iterator_concepts.h (ranges::__cust_imove::_IMove):
            Add trait to determine return type and an alias for it.
            (ranges::__cust_imove::_IMove::operator()): Use __result instead of
            deduced return type.
            (iter_rvalue_reference_t): Use _IMove::__type instead of checking
            the result of ranges::iter_move.
            (__detail::__indirectly_readable_impl): Use iter_rvalue_reference_t
            instead of checking the result of ranges::iter_move.
            * testsuite/24_iterators/customization_points/92894.cc: New test.
            * testsuite/24_iterators/indirect_callable/92894.cc: New test.

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2020-05-01 13:28 ` cvs-commit at gcc dot gnu.org
@ 2020-05-01 15:52 ` redi at gcc dot gnu.org
  2020-05-07 11:56 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-01 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on master (GCC 11) so far.

Clang's error is a bit more explicit about the problem:

error: function 'std::projected<X *, std::identity>::operator*' is used but not
defined in this translation unit, and cannot be defined in any other
translation unit because its type does not have linkage

For a type with external linkage the ranges::iter_move::operator() function
still gets instantiated, but the compiler doesn't reject it immediately because
it's possible that projected<X*, identity>::operator* is defined in another
translation unit. Since the function isn't actually called (just instantiated
to find its return type) there's no reference to it in the final object, and so
it doesn't matter that projected::operator* isn't defined anywhere. The program
is still ill-formed, but no diagnostic is required and it "works".

For a type with internal linkage (like a local class) the compiler stops
immediately, diagnosing the ill-formed call to projected::operator*. So without
this fix it's not possible to use most std::ranges:: algos with local classes.

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2020-05-01 15:52 ` redi at gcc dot gnu.org
@ 2020-05-07 11:56 ` jakub at gcc dot gnu.org
  2020-05-07 20:07 ` cvs-commit at gcc dot gnu.org
  2020-05-07 20:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-07 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.0                        |10.2

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.1 has been released.

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2020-05-07 11:56 ` jakub at gcc dot gnu.org
@ 2020-05-07 20:07 ` cvs-commit at gcc dot gnu.org
  2020-05-07 20:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-07 20:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:6fedf28c7921f125be75a9f688a7b845a1b5663b

commit r10-8121-g6fedf28c7921f125be75a9f688a7b845a1b5663b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 7 17:39:56 2020 +0100

    libstdc++: Replace deduced return type in ranges::iter_move (PR 92894)

    The deduced return type causes the instantiation of the function body,
    which can then require the instantiation of std::projected::operator*
    which is intentionally not defined.

    This patch uses a helper trait to define the return type, so that the
    function body doesn't need to be instantiated.

    Unlike on the master branch, this backport to gcc-10 does not change the
    iter_rvalue_reference_t alias template and __indirectly_readable_impl
    concept to use the new trait.

    Backport from mainline
    2020-05-01  Jonathan Wakely  <jwakely@redhat.com>
                Patrick Palka  <ppalka@redhat.com>

            PR libstdc++/92894
            * include/bits/iterator_concepts.h (ranges::__cust_imove::_IMove):
            Add trait to determine return type and an alias for it.
            (ranges::__cust_imove::_IMove::operator()): Use __result instead of
            deduced return type.
            * testsuite/24_iterators/customization_points/92894.cc: New test.
            * testsuite/24_iterators/indirect_callable/92894.cc: New test.

    Co-authored-by: Patrick Palka <ppalka@redhat.com>

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

* [Bug libstdc++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction
       [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2020-05-07 20:07 ` cvs-commit at gcc dot gnu.org
@ 2020-05-07 20:08 ` redi at gcc dot gnu.org
  10 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-07 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 10.2

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

end of thread, other threads:[~2020-05-07 20:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-92894-4@http.gcc.gnu.org/bugzilla/>
2020-03-20 21:07 ` [Bug c++/92894] "declared using local type 'test01()::X', is used but never defined" during concept satisfaction redi at gcc dot gnu.org
2020-03-20 21:08 ` redi at gcc dot gnu.org
2020-05-01  2:43 ` ppalka at gcc dot gnu.org
2020-05-01  2:53 ` ppalka at gcc dot gnu.org
2020-05-01  8:07 ` redi at gcc dot gnu.org
2020-05-01 10:35 ` [Bug libstdc++/92894] " redi at gcc dot gnu.org
2020-05-01 13:28 ` cvs-commit at gcc dot gnu.org
2020-05-01 15:52 ` redi at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-05-07 20:07 ` cvs-commit at gcc dot gnu.org
2020-05-07 20:08 ` redi 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).