public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108335] New: New-expression doesn't perform mandatory copy elision when copy constructor is disabled with `requires`, in a template
@ 2023-01-08  8:02 iamsupermouse at mail dot ru
  0 siblings, 0 replies; only message in thread
From: iamsupermouse at mail dot ru @ 2023-01-08  8:02 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108335
           Summary: New-expression doesn't perform mandatory copy elision
                    when copy constructor is disabled with `requires`, in
                    a template
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamsupermouse at mail dot ru
  Target Milestone: ---

This doesn't compile, but it should:

    template <typename T>
    struct A
    {
        A(int) {}
        A(const A &) requires false {}; // The condititon can depend on `T`, it
doesn't matter.
    };

    template <typename>
    void foo()
    {
        new A<int>(A<int>(1));
    }

    int main()
    {
        foo<int>();
    }

GCC says it doesn't have a suitable constructor to perform the copy.

This starts working if I make `foo()` a non-template, or =delete `A(const A
&)`, or create the object without `new`.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-08  8:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08  8:02 [Bug c++/108335] New: New-expression doesn't perform mandatory copy elision when copy constructor is disabled with `requires`, in a template iamsupermouse at mail dot ru

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