public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]()
@ 2020-10-21 19:05 mpolacek at gcc dot gnu.org
  2020-10-21 19:05 ` [Bug c++/97523] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-21 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97523
           Summary: [11 Regression] bogus "would use explicit constructor"
                    error for new[]()
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

Since my r11-3092 the following is rejected with -std=c++20:

template <typename> struct A;
template <typename T> struct A<T[]> { typedef T type; };
template <typename T> using U = typename A<T>::type;

struct B {
  template <typename T> B(T);
};

long int sz;

template <typename T> void foo() { new U<T>[sz](); }

struct D {
  explicit D();
};

struct C {
  B b;
  C() : b(foo<D[]>) {}
};


r.cc: In instantiation of ‘void foo() [with T = D []]’:
r.cc:19:9:   required from here
r.cc:11:36: error: converting to ‘U<D []>’ {aka ‘D’} from initializer list
would use explicit constructor ‘D::D()’
   11 | template <typename T> void foo() { new U<T>[sz](); }
      |

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

* [Bug c++/97523] [11 Regression] bogus "would use explicit constructor" error for new[]()
  2020-10-21 19:05 [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]() mpolacek at gcc dot gnu.org
@ 2020-10-21 19:05 ` mpolacek at gcc dot gnu.org
  2020-11-18 16:47 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-21 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-10-21
   Target Milestone|---                         |11.0
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
           Keywords|                            |rejects-valid
           Priority|P3                          |P1

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

* [Bug c++/97523] [11 Regression] bogus "would use explicit constructor" error for new[]()
  2020-10-21 19:05 [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]() mpolacek at gcc dot gnu.org
  2020-10-21 19:05 ` [Bug c++/97523] " mpolacek at gcc dot gnu.org
@ 2020-11-18 16:47 ` mpolacek at gcc dot gnu.org
  2020-11-19 19:00 ` cvs-commit at gcc dot gnu.org
  2020-11-19 19:02 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-11-18 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Better test:

// PR c++/97523
// { dg-do compile }

struct T {
  explicit T();
  T(int);
};

void
fn (int n)
{
  new T[1]();
  new T[2]();
  new T[3]();
  new T[n]();
#if __cpp_aggregate_paren_init
  new T[]();
  new T[2](1, 2);
  new T[3](1, 2);
#endif
}

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

* [Bug c++/97523] [11 Regression] bogus "would use explicit constructor" error for new[]()
  2020-10-21 19:05 [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]() mpolacek at gcc dot gnu.org
  2020-10-21 19:05 ` [Bug c++/97523] " mpolacek at gcc dot gnu.org
  2020-11-18 16:47 ` mpolacek at gcc dot gnu.org
@ 2020-11-19 19:00 ` cvs-commit at gcc dot gnu.org
  2020-11-19 19:02 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-19 19:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:ae48b74ca0c0ba33d396a6ebad7a1c0a6dadb1f7

commit r11-5179-gae48b74ca0c0ba33d396a6ebad7a1c0a6dadb1f7
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Nov 18 19:07:07 2020 -0500

    c++: Fix array new with value-initialization [PR97523]

    Since my r11-3092 the following is rejected with -std=c++20:

      struct T { explicit T(); };
      void fn(int n) {
        new T[1]();
      }

    with "would use explicit constructor 'T::T()'".  It is because since
    that change we go into the P1009 block in build_new (array_p is false,
    but nelts is non-null and we're in C++20).  Since we only have (), we
    build a {} and continue to build_new_1, which then calls build_vec_init
    and then we error because the {} isn't CONSTRUCTOR_IS_DIRECT_INIT.

    For (), which is value-initializing, we want to do what we were doing
    before: pass empty init and let build_value_init take care of it.

    For various reasons I wanted to dig a little bit deeper into this,
    and as a result, I'm adding a test for [expr.new]/24 (and checked that
    out current behavior matches clang++).

    gcc/cp/ChangeLog:

            PR c++/97523
            * init.c (build_new): When value-initializing an array new,
            leave the INIT as an empty vector.

    gcc/testsuite/ChangeLog:

            PR c++/97523
            * g++.dg/expr/anew5.C: New test.
            * g++.dg/expr/anew6.C: New test.

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

* [Bug c++/97523] [11 Regression] bogus "would use explicit constructor" error for new[]()
  2020-10-21 19:05 [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]() mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-11-19 19:00 ` cvs-commit at gcc dot gnu.org
@ 2020-11-19 19:02 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-11-19 19:02 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2020-11-19 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21 19:05 [Bug c++/97523] New: [11 Regression] bogus "would use explicit constructor" error for new[]() mpolacek at gcc dot gnu.org
2020-10-21 19:05 ` [Bug c++/97523] " mpolacek at gcc dot gnu.org
2020-11-18 16:47 ` mpolacek at gcc dot gnu.org
2020-11-19 19:00 ` cvs-commit at gcc dot gnu.org
2020-11-19 19:02 ` mpolacek 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).