public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106538] New: Reject-valid: Substitution failure causes error with unsatisfied constraint
@ 2022-08-05 15:42 dv at vollmann dot ch
  2022-08-08 15:06 ` [Bug c++/106538] " ppalka at gcc dot gnu.org
  2022-08-08 18:31 ` dv at vollmann dot ch
  0 siblings, 2 replies; 3+ messages in thread
From: dv at vollmann dot ch @ 2022-08-05 15:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106538
           Summary: Reject-valid: Substitution failure causes error with
                    unsatisfied constraint
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dv at vollmann dot ch
  Target Milestone: ---

Created attachment 53417
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53417&action=edit
Example program that produces the error

If in the attached program ADD_CONSTRAINED_OVERLOAD is defined, the tag_invoke
for connect_t is instantiated.
This instantiation fails for a number of reasons so GCC should continue with
the next overload.  However in this case GCC rejects the code claiming the
contrained is not satisfied (which is correct, but shouldn't cause a reject).

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

* [Bug c++/106538] Reject-valid: Substitution failure causes error with unsatisfied constraint
  2022-08-05 15:42 [Bug c++/106538] New: Reject-valid: Substitution failure causes error with unsatisfied constraint dv at vollmann dot ch
@ 2022-08-08 15:06 ` ppalka at gcc dot gnu.org
  2022-08-08 18:31 ` dv at vollmann dot ch
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-08-08 15:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |DUPLICATE

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Thanks for the bug report.  It's somewhat unintuitive, but I believe GCC is
correct to reject this testcase.  I think other compilers accept it because
they don't fully implement wg21.link/cwg2369 which moved the constraint
satisfaction check during template argument deduction to _before_ checking
non-dependent conversions.  This means that during overload resolution for the
call

  tag_invoke(sync_wait_t{}, sch, s)

we need to check satisfaction of the receiver<Recv> constraint on the candidate

  template <receiver Recv>
  friend constexpr auto tag_invoke(connect_t, Sender, Recv &&)

despite the type sync_wait_t of the first argument not being convertible to
connect_t, and it's during satisfaction that we encounter the hard error. 
Before CWG2369 we'd check non-dependent conversions first, and then check
constraints, so we'd discard this candidate without having to check its
constraints and avoid the hard error.

One way to work around this is to encode the non-dependent conversion as an
additional constraint that's checked first:

#ifdef ADD_CONSTRAINED_OVERLOAD
        template <std::convertible_to<connect_t> T, receiver Recv>
        friend constexpr auto tag_invoke(T, Sender, Recv &&)
        {
            return Op{};
        }
#endif

Another workaround is to make set_done_t::operator() more SFINAE-friendly by
giving it a non-deduced return type, so that ill-formed calls to it don't end
up being a hard error:

    template <typename Recv>                        
    auto operator()(Recv &&r) const noexcept        
        -> decltype(tag_invoke(*this, (Recv&&)r));

See also PR99599 / PR97704.

*** This bug has been marked as a duplicate of bug 99599 ***

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

* [Bug c++/106538] Reject-valid: Substitution failure causes error with unsatisfied constraint
  2022-08-05 15:42 [Bug c++/106538] New: Reject-valid: Substitution failure causes error with unsatisfied constraint dv at vollmann dot ch
  2022-08-08 15:06 ` [Bug c++/106538] " ppalka at gcc dot gnu.org
@ 2022-08-08 18:31 ` dv at vollmann dot ch
  1 sibling, 0 replies; 3+ messages in thread
From: dv at vollmann dot ch @ 2022-08-08 18:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from dv at vollmann dot ch ---
Thanks for the detailed explanation (and the workarounds!).
I still think it's very surprising behaviour, but I'll probably leave it to
others to bring this to WG21.

Thanks again,
  Detlef

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

end of thread, other threads:[~2022-08-08 18:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 15:42 [Bug c++/106538] New: Reject-valid: Substitution failure causes error with unsatisfied constraint dv at vollmann dot ch
2022-08-08 15:06 ` [Bug c++/106538] " ppalka at gcc dot gnu.org
2022-08-08 18:31 ` dv at vollmann dot ch

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).