public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor
@ 2021-06-17 19:34 gcc at nospam dot scs.stanford.edu
  2021-06-17 21:49 ` [Bug c++/101113] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gcc at nospam dot scs.stanford.edu @ 2021-06-17 19:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101113
           Summary: g++ thinks constructor suppressed by a requires clause
                    is actually a bad copy constructor
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at nospam dot scs.stanford.edu
  Target Milestone: ---

g++ 11.1.0 is rejecting the following correct code when compiling with
`-std=c++20` (test case public domain):

template<bool B> struct S {
  S() {}
  S(S<false>) requires B {}
};
S<false> sf;

Here is the error message:

$ g++ -std=c++20 -c test.cc
y.cc: In instantiation of 'struct S<false>':
y.cc:3:26:   required from here
y.cc:3:3: error: invalid constructor; you probably meant 'S<false> (const
S<false>&)'
    3 |   S(S<false>) requires B {}
      |   ^

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

* [Bug c++/101113] g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor
  2021-06-17 19:34 [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor gcc at nospam dot scs.stanford.edu
@ 2021-06-17 21:49 ` redi at gcc dot gnu.org
  2021-06-22 20:40 ` rs2740 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-17 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-06-17
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Confirmed. Fails with older versions too and doesn't seem to be a regression.

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

* [Bug c++/101113] g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor
  2021-06-17 19:34 [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor gcc at nospam dot scs.stanford.edu
  2021-06-17 21:49 ` [Bug c++/101113] " redi at gcc dot gnu.org
@ 2021-06-22 20:40 ` rs2740 at gmail dot com
  2021-06-23  3:46 ` gcc at nospam dot scs.stanford.edu
  2023-11-29  4:53 ` gcc at nospam dot scs.stanford.edu
  3 siblings, 0 replies; 5+ messages in thread
From: rs2740 at gmail dot com @ 2021-06-22 20:40 UTC (permalink / raw)
  To: gcc-bugs

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

TC <rs2740 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rs2740 at gmail dot com

--- Comment #2 from TC <rs2740 at gmail dot com> ---
https://eel.is/c++draft/class.copy.ctor#5

I don't think this code is valid. The constraint (which isn't checked until
overload resolution time anyway) can't suppress the outright ill-formedness of
the declaration.

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

* [Bug c++/101113] g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor
  2021-06-17 19:34 [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor gcc at nospam dot scs.stanford.edu
  2021-06-17 21:49 ` [Bug c++/101113] " redi at gcc dot gnu.org
  2021-06-22 20:40 ` rs2740 at gmail dot com
@ 2021-06-23  3:46 ` gcc at nospam dot scs.stanford.edu
  2023-11-29  4:53 ` gcc at nospam dot scs.stanford.edu
  3 siblings, 0 replies; 5+ messages in thread
From: gcc at nospam dot scs.stanford.edu @ 2021-06-23  3:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from David Mazieres <gcc at nospam dot scs.stanford.edu> ---
(In reply to TC from comment #2)
> https://eel.is/c++draft/class.copy.ctor#5
> 
> I don't think this code is valid. The constraint (which isn't checked until
> overload resolution time anyway) can't suppress the outright ill-formedness
> of the declaration.

Admittedly, 11.4.5.3/5 makes no mention of constraints:

A declaration of a constructor for a class X is ill-formed if its first
parameter is of type cv X and either there are no other parameters or else all
other parameters have default arguments.
A member function template is never instantiated to produce such a constructor
signature.
- https://timsong-cpp.github.io/cppwp/n4868/class.copy.ctor#5

On the other hand, suppressed functions should not participate in overload
resolution.  Here's some normative language to the same effect 12.4.3/3:

Second, for a function to be viable, if it has associated constraints
([temp.constr.decl]), those constraints shall be satisfied
([temp.constr.constr]).
- https://timsong-cpp.github.io/cppwp/n4868/over.match.viable#3

So here's another example that doesn't involve 11.4.5.3/5:

#include <type_traits>

template<typename T> struct S2 {
  static T *fn() requires (!std::is_reference_v<T>) { return nullptr; }
  static std::nullptr_t fn() requires std::is_reference_v<T> { return {}; }
};

void
f()
{
  auto p = S2<int&>::fn();
}

$ g++ -std=c++20    -c -o constructor.o constructor.cc
constructor.cc: In instantiation of 'struct S2<int&>':
constructor.cc:11:20:   required from here
constructor.cc:4:13: error: forming pointer to reference type 'int&'
    4 |   static T *fn() requires (!std::is_reference_v<T>) { return nullptr; }
      |             ^~
make: *** [<builtin>: constructor.o] Error 1

So I guess your argument is that there's a certain level of well-formedness
required even before the constraints can be evaluated, and an X::X(X) method is
as non-sensical as a type like "int&*".  That seems like a reasonable position,
though I wish the standard were more explicit.

I apologize for wasting your time if this was a bogus bug report.

For the record, in case the closed bug report comes up in anyone's web search,
an easy fix is to rely on the fact that templates won't be instantiated to bad
copy constructors:

template<bool B> struct S {
  S() {}
  template<bool B2> S(S<B2>) requires B2 {}
};
S<false> sf;
S<true> st;

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

* [Bug c++/101113] g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor
  2021-06-17 19:34 [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor gcc at nospam dot scs.stanford.edu
                   ` (2 preceding siblings ...)
  2021-06-23  3:46 ` gcc at nospam dot scs.stanford.edu
@ 2023-11-29  4:53 ` gcc at nospam dot scs.stanford.edu
  3 siblings, 0 replies; 5+ messages in thread
From: gcc at nospam dot scs.stanford.edu @ 2023-11-29  4:53 UTC (permalink / raw)
  To: gcc-bugs

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

David Mazières <gcc at nospam dot scs.stanford.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from David Mazières <gcc at nospam dot scs.stanford.edu> ---
Sorry I should have closed this bug report a while ago when I said it wasn't a
bug.

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

end of thread, other threads:[~2023-11-29  4:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 19:34 [Bug c++/101113] New: g++ thinks constructor suppressed by a requires clause is actually a bad copy constructor gcc at nospam dot scs.stanford.edu
2021-06-17 21:49 ` [Bug c++/101113] " redi at gcc dot gnu.org
2021-06-22 20:40 ` rs2740 at gmail dot com
2021-06-23  3:46 ` gcc at nospam dot scs.stanford.edu
2023-11-29  4:53 ` gcc at nospam dot scs.stanford.edu

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