public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96170] New: Enhancement: allow requires-clause checking of statement expression substitution success or failure
@ 2020-07-11 20:22 wjwray at gmail dot com
  2020-07-12 15:51 ` [Bug c++/96170] " wjwray at gmail dot com
  2020-07-13 13:30 ` wjwray at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: wjwray at gmail dot com @ 2020-07-11 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96170
           Summary: Enhancement: allow requires-clause checking of
                    statement expression substitution success or failure
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wjwray at gmail dot com
  Target Milestone: ---

Some sort of sfinae on statement expressions containing structured bindings
can provide a convenient way to detect the number of bindings in a type.

Checking in requires clauses seems like the most direct approach:
https://godbolt.org/z/Eoq9rr

    template <typename T> constexpr int arity()
    {
           if constexpr (requires (T& a) { ({auto [x] = a;}); })   return 1;
      else if constexpr (requires (T& a) { ({auto [x,y] = a;}); }) return 2;
      //   ... etc ... 3,4,5 ... N
      else
           return 0;
    };

G++ accepts the template and, 
for a type T that decomposes into 1 element, arity<T>() == 1 succeeds.

However, it fails eagerly on the 1st condition for any other type,
e.g. arity<int>(), arity<int[2]>(), &etc...

c.f. bug 92402 seeking to match Clang's ability to sfinae in other contexts

(Clang accepts the template above but returns 0 for all T.)

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

* [Bug c++/96170] Enhancement: allow requires-clause checking of statement expression substitution success or failure
  2020-07-11 20:22 [Bug c++/96170] New: Enhancement: allow requires-clause checking of statement expression substitution success or failure wjwray at gmail dot com
@ 2020-07-12 15:51 ` wjwray at gmail dot com
  2020-07-13 13:30 ` wjwray at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: wjwray at gmail dot com @ 2020-07-12 15:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Will Wray <wjwray at gmail dot com> ---
Opened an equivalent enhancement request for Clang
https://bugs.llvm.org/show_bug.cgi?id=46691

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

* [Bug c++/96170] Enhancement: allow requires-clause checking of statement expression substitution success or failure
  2020-07-11 20:22 [Bug c++/96170] New: Enhancement: allow requires-clause checking of statement expression substitution success or failure wjwray at gmail dot com
  2020-07-12 15:51 ` [Bug c++/96170] " wjwray at gmail dot com
@ 2020-07-13 13:30 ` wjwray at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: wjwray at gmail dot com @ 2020-07-13 13:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Will Wray <wjwray at gmail dot com> ---
A much better idea, submitted here as bug 96185
and simultaneously submitted to Clang and MSVC -
a portable builtin to count bindings in [dcl.struct.bind]

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

end of thread, other threads:[~2020-07-13 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11 20:22 [Bug c++/96170] New: Enhancement: allow requires-clause checking of statement expression substitution success or failure wjwray at gmail dot com
2020-07-12 15:51 ` [Bug c++/96170] " wjwray at gmail dot com
2020-07-13 13:30 ` wjwray at gmail dot com

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