public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type
@ 2014-11-20 17:39 roger.ferrer at bsc dot es
  2014-11-20 17:41 ` [Bug c++/64002] " roger.ferrer at bsc dot es
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: roger.ferrer at bsc dot es @ 2014-11-20 17:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64002
           Summary: Braced initialization of unknown bound array of
                    nondependent type
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roger.ferrer at bsc dot es

Hi,

during an initialization of an array of unknown bound of
non-dependent type using a braced initializer which contains
type-dependent expressions, g++ does not "postpone" the computation
of the array size at instantiation time and seems to use the number
of elements inside the braced-initializer.

In all cases the code compiles fine.

  #include <cassert>

  struct A
  {
    int x, y;
  };

  template <typename T>
  int f1(T t1, T t2)
  {
    A a[] = { t1, t2 };
    return sizeof(a) / sizeof(a[0]);
  }

  void test1()
  {
    assert(f1(A(), A()) == 2); // OK
    assert(f1(1, 2) == 1); // ERROR: this assert fails at runtime
  }

That said, in the context of C++2011 a parameter pack expansion seems to work
correctly.

  template <typename ...T>
  int f2(T ...n)
  {
    A a[] = { n... };
    return sizeof(a) / sizeof(a[0]);
  }

  void test2()
  {
    assert(f2(A(), A()) == 2); // OK
    assert(f2(1, 2) == 1); // OK
  }

All asserts pass correctly both in clang-3.5 and icc 14.0.2

Kind regards,


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

* [Bug c++/64002] Braced initialization of unknown bound array of nondependent type
  2014-11-20 17:39 [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type roger.ferrer at bsc dot es
@ 2014-11-20 17:41 ` roger.ferrer at bsc dot es
  2014-12-10 20:38 ` ville.voutilainen at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: roger.ferrer at bsc dot es @ 2014-11-20 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Roger Ferrer Ibanez <roger.ferrer at bsc dot es> ---
Created attachment 34055
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34055&action=edit
Small testcase


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

* [Bug c++/64002] Braced initialization of unknown bound array of nondependent type
  2014-11-20 17:39 [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type roger.ferrer at bsc dot es
  2014-11-20 17:41 ` [Bug c++/64002] " roger.ferrer at bsc dot es
@ 2014-12-10 20:38 ` ville.voutilainen at gmail dot com
  2015-08-13 10:51 ` paolo.carlini at oracle dot com
  2023-12-11 17:50 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-12-10 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-10
                 CC|                            |ville.voutilainen at gmail dot com
     Ever confirmed|0                           |1


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

* [Bug c++/64002] Braced initialization of unknown bound array of nondependent type
  2014-11-20 17:39 [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type roger.ferrer at bsc dot es
  2014-11-20 17:41 ` [Bug c++/64002] " roger.ferrer at bsc dot es
  2014-12-10 20:38 ` ville.voutilainen at gmail dot com
@ 2015-08-13 10:51 ` paolo.carlini at oracle dot com
  2023-12-11 17:50 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-08-13 10:51 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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

* [Bug c++/64002] Braced initialization of unknown bound array of nondependent type
  2014-11-20 17:39 [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type roger.ferrer at bsc dot es
                   ` (2 preceding siblings ...)
  2015-08-13 10:51 ` paolo.carlini at oracle dot com
@ 2023-12-11 17:50 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-12-11 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=104302
             Status|NEW                         |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.0

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12+ by r12-7010-g501c4ee9fad687 whose testcase array36.C is very
similar to this one.

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

end of thread, other threads:[~2023-12-11 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-20 17:39 [Bug c++/64002] New: Braced initialization of unknown bound array of nondependent type roger.ferrer at bsc dot es
2014-11-20 17:41 ` [Bug c++/64002] " roger.ferrer at bsc dot es
2014-12-10 20:38 ` ville.voutilainen at gmail dot com
2015-08-13 10:51 ` paolo.carlini at oracle dot com
2023-12-11 17:50 ` ppalka 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).