public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range
@ 2021-12-26 11:33 hewillk at gmail dot com
  2021-12-26 15:41 ` [Bug libstdc++/103831] " ppalka at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: hewillk at gmail dot com @ 2021-12-26 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103831
           Summary: views::lazy_split accepts Pattern as span<int, 1> when
                    V is input_range
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

This is an extremely strange case that I suspect is a language bug, consider:

  #include <ranges>
  #include <array>
  #include <stream>
  #include <span>
  int main() {
    auto ints = std::istringstream{"42"};
    auto r = std::ranges::istream_view<int>(ints);
    std::array<int, 1> arr{42};
    std::span p{arr};
    std::ranges::lazy_split_view s(r, p);
  }

https://godbolt.org/z/o9EY9oPx6

In the above example, lazy_split_view should be rejected.
According to [range.lazy.split.view], when V does not model forward_range,
Pattern must be a tiny_range, however, span<int, 1> does not model tiny_range
since it does not have a static size function, so lazy_split_view should be
ill-formed. 
I really don’t know why it will still be accepted.

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

* [Bug libstdc++/103831] views::lazy_split accepts Pattern as span<int, 1> when V is input_range
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
@ 2021-12-26 15:41 ` ppalka at gcc dot gnu.org
  2021-12-26 16:21 ` [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this' hewillk at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-12-26 15:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
   Last reconfirmed|                            |2021-12-26
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Interestingly, adding the (correct and passing) assert

  static_assert(!std::ranges::__detail::__tiny_range<decltype(p)>);

before the last line causes us to reject the last line with

  /home/patrick/code/gcc/libstdc++-v3/include/std/ranges:2953:12: error:
satisfaction value of atomic constraint
‘requires{std::ranges::__detail::__require_constant<(std::remove_reference<_Tp>::type::size)()>;}
[with _Range = std::span<int, 1>]’ changed from ‘false’ to ‘true’


Looks like this is indeed a frontend bug, which can be distilled into the
testcase

struct A {
  constexpr int size() { return 42; }
};

template<class T>
struct B : T {
  static_assert(A::size() == 42);
};

We incorrectly accept the non-dependent call A::size() here even though it's
being performed from a context where there is no 'this' object.

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

* [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this'
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
  2021-12-26 15:41 ` [Bug libstdc++/103831] " ppalka at gcc dot gnu.org
@ 2021-12-26 16:21 ` hewillk at gmail dot com
  2022-01-11 18:00 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: hewillk at gmail dot com @ 2021-12-26 16:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
Please let me add a digression, is the standard overconstrained the definition
of tiny_range? 
In the current standard, it seems that only single_view and empty_view satisfy
tiny_range. However, std::array<int, 1> and span<int, 1> or even int[1], in my
opinion, should be valid Pattern types when V is an input_range, because we can
directly extract their size from the type, but none of the three have a static
size() function. This also means that the constructor lazy_split_view(R&&, P&&)
has an *extremely* limited set of P when R is an input_range.

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

* [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this'
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
  2021-12-26 15:41 ` [Bug libstdc++/103831] " ppalka at gcc dot gnu.org
  2021-12-26 16:21 ` [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this' hewillk at gmail dot com
@ 2022-01-11 18:00 ` cvs-commit at gcc dot gnu.org
  2022-01-12 17:03 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-11 18:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:0378f563b0321c44c4a9c98cf46d2a22b9160f76

commit r12-6485-g0378f563b0321c44c4a9c98cf46d2a22b9160f76
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jan 11 13:00:48 2022 -0500

    c++: dependent bases and 'this' availability [PR103831]

    Here during satisfaction of B's constraints we're failing to reject the
    object-less call to the non-static member function A::size ultimately
    because satisfaction is performed in the (access) context of the class
    template B, which has a dependent base, and so the any_dependent_bases_p
    check within build_new_method_call causes us to not reject the call.
    (Subsequent constexpr evaluation of the call succeeds since the function
    is effectively static.)

    This patch fixes this by refining the any_dependent_bases_p check within
    build_new_method_call: if we're in a context where 'this' is unavailable,
    then we cannot resolve the implicit object regardless of the presence of
    a dependent base.  So let's also check current_class_ptr alongside a_d_b_p.

            PR c++/103831

    gcc/cp/ChangeLog:

            * call.c (build_new_method_call): Consider dependent bases only
            if 'this' is available.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-class3.C: New test.
            * g++.dg/template/non-dependent18.C: New test.

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

* [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this'
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2022-01-11 18:00 ` cvs-commit at gcc dot gnu.org
@ 2022-01-12 17:03 ` cvs-commit at gcc dot gnu.org
  2022-01-12 17:25 ` ppalka at gcc dot gnu.org
  2022-01-12 17:26 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-12 17:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:614a9580d4463c4aefd74c40ed46bfab2bef65c7

commit r11-9456-g614a9580d4463c4aefd74c40ed46bfab2bef65c7
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Jan 11 13:00:48 2022 -0500

    c++: dependent bases and 'this' availability [PR103831]

    Here during satisfaction of B's constraints we're failing to reject the
    object-less call to the non-static member function A::size ultimately
    because satisfaction is performed in the (access) context of the class
    template B, which has a dependent base, and so the any_dependent_bases_p
    check within build_new_method_call causes us to not reject the call.
    (Subsequent constexpr evaluation of the call succeeds since the function
    is effectively static.)

    This patch fixes this by refining the any_dependent_bases_p check within
    build_new_method_call: if we're in a context where 'this' is unavailable,
    then we cannot resolve the implicit object regardless of the presence of
    a dependent base.  So let's also check current_class_ptr alongside a_d_b_p.

            PR c++/103831

    gcc/cp/ChangeLog:

            * call.c (build_new_method_call): Consider dependent bases only
            if 'this' is available.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-class3.C: New test.
            * g++.dg/template/non-dependent18.C: New test.

    (cherry picked from commit 0378f563b0321c44c4a9c98cf46d2a22b9160f76)

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

* [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this'
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2022-01-12 17:03 ` cvs-commit at gcc dot gnu.org
@ 2022-01-12 17:25 ` ppalka at gcc dot gnu.org
  2022-01-12 17:26 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-12 17:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to 康桓瑋 from comment #2)
> Please let me add a digression, is the standard overconstrained the
> definition of tiny_range? 
> In the current standard, it seems that only single_view and empty_view
> satisfy tiny_range. However, std::array<int, 1> and span<int, 1> or even
> int[1], in my opinion, should be valid Pattern types when V is an
> input_range, because we can directly extract their size from the type, but
> none of the three have a static size() function. This also means that the
> constructor lazy_split_view(R&&, P&&) has an *extremely* limited set of P
> when R is an input_range.

That sounds reasonable to me FWIW.  I believe the process for making such a
change starts with sending a proposal paper to LEWG for consideration.  I'm not
sure if there are any existing papers about this.

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

* [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this'
  2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2022-01-12 17:25 ` ppalka at gcc dot gnu.org
@ 2022-01-12 17:26 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-12 17:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.3
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Should be fixed for GCC 11.3/12

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

end of thread, other threads:[~2022-01-12 17:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-26 11:33 [Bug libstdc++/103831] New: views::lazy_split accepts Pattern as span<int, 1> when V is input_range hewillk at gmail dot com
2021-12-26 15:41 ` [Bug libstdc++/103831] " ppalka at gcc dot gnu.org
2021-12-26 16:21 ` [Bug c++/103831] non-dependent call to non-static member function not rejected ahead of time when there are dependent bases and no 'this' hewillk at gmail dot com
2022-01-11 18:00 ` cvs-commit at gcc dot gnu.org
2022-01-12 17:03 ` cvs-commit at gcc dot gnu.org
2022-01-12 17:25 ` ppalka at gcc dot gnu.org
2022-01-12 17:26 ` ppalka 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).