From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9204 invoked by alias); 6 May 2012 11:22:18 -0000 Received: (qmail 9194 invoked by uid 22791); 6 May 2012 11:22:17 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 06 May 2012 11:22:03 +0000 From: "daniel.kruegler at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/53248] std::array doesn't work when T is not default-constructible Date: Sun, 06 May 2012 11:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.kruegler at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-05/txt/msg00625.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53248 --- Comment #3 from Daniel Kr=C3=BCgler 2012-05-06 11:21:47 UTC --- (In reply to comment #2) > Daniel, can you see other options besides adding a specialization? (which= would > be a straightforward task, I may even get around to do pretty soon when I= will > do debug-mode std::array, already in my todo list) I haven't implemented it completely, but an alternative to a partial specialization could be something like the following: template struct __array_data_traits { typedef T type[N]; }; template struct __array_data_traits { struct type {}; }; template struct array { typename __array_data_traits::type elems; }; array ai1 =3D {1}; array ai1b =3D {}; array ai0 =3D {}; The sole (?) disadvantage of this approach would be that std::is_empty> does not evaluate to true. But all the specialization-relevant logic could also be added to __array_data_traits in terms of static (constexpr where possible) functions. Technically the traits-based approach would be preferable, because otherwis= e I see the risk that user-code that itself would try to specialize std::array = with some T for a user-provided type could notice the difference. Consider: // Within Library: template struct array { T elems[N]; }; template struct array { }; // User world: struct User {}; template struct array { User elems[N > 0 ? N : 1]; }; array au0 =3D {}; // Error, ambiguous The problem with the current library wording is that it does not *explicitl= y* allow a *specialization* for std::array (in contrast to vector or to numeric_limits for cv-variations of the actual type), therefore I believe t= hat from the current wording state a partial-specialization by the library is borderline to invalid, at least a gray zone, because of the need to support [namespace.std] p1. If a library issue should be submitted, I would suggest to provide the libr= ary the freedom for providing a special for the zero-size case.