public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
@ 2015-03-08 16:49 kariya_mitsuru at hotmail dot com
  2015-03-08 16:50 ` [Bug c/65350] " kariya_mitsuru at hotmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-08 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65350
           Summary: [C++14] operator new[] should not be called if # of
                    initializer elements exceeds # of elements
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

Please see the sample code below.

========================== sample code ==========================
#include <iostream>
#include <new>

void* operator new[](std::size_t size)
{
    std::cout << "my operator new[](" << size << ")" << std::endl;
    return ::operator new(size);
}

int main()
{
    int i = 1;
    try {
        int* p = new int[i]{ 1, 2 };
        delete[] p;
    } catch (const std::bad_array_new_length& e) {
        std::cout << e.what() << std::endl;
    }
}
========================== sample code ==========================
========================== output ==========================
my operator new[](4)
std::bad_array_new_length
========================== output ==========================

cf. http://melpon.org/wandbox/permlink/tQFp5fpPXT5mZu34

The C++14 standard 5.3.4[expr.new]/p.7 says,

  The expression in a noptr-new-declarator is erroneous if:

    ...

    --- the new-initializer is a braced-init-list and the number of array
elements
        for which initializers are provided (including the terminating '\0' in
a
        string literal (2.13.5)) exceeds the number of elements to initialize.

  ... Otherwise, a new-expression with an erroneous expression **does not call
  an allocation function** and terminates by throwing an exception of a type
  that would match a handler (15.3) of type std::bad_array_new_length
(18.6.2.2).
  ...

(emphasis mine)

So, I think that the sample code above should output only
========================== output ==========================
std::bad_array_new_length
========================== output ==========================


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

* [Bug c/65350] [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
  2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
@ 2015-03-08 16:50 ` kariya_mitsuru at hotmail dot com
  2015-03-13  3:51 ` [Bug c++/65350] " hubicka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-08 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
Created attachment 34985
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34985&action=edit
g++ -v


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

* [Bug c++/65350] [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
  2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
  2015-03-08 16:50 ` [Bug c/65350] " kariya_mitsuru at hotmail dot com
@ 2015-03-13  3:51 ` hubicka at gcc dot gnu.org
  2015-03-13 10:15 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hubicka at gcc dot gnu.org @ 2015-03-13  3:51 UTC (permalink / raw)
  To: gcc-bugs

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

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org
          Component|c                           |c++

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Correcting component as pointed out by NightStrike.


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

* [Bug c++/65350] [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
  2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
  2015-03-08 16:50 ` [Bug c/65350] " kariya_mitsuru at hotmail dot com
  2015-03-13  3:51 ` [Bug c++/65350] " hubicka at gcc dot gnu.org
@ 2015-03-13 10:15 ` redi at gcc dot gnu.org
  2021-08-09 21:09 ` pinskia at gcc dot gnu.org
  2023-09-07  5:17 ` gayathri.gottumukkala.27 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-13 10:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-13
     Ever confirmed|0                           |1


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

* [Bug c++/65350] [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
  2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
                   ` (2 preceding siblings ...)
  2015-03-13 10:15 ` redi at gcc dot gnu.org
@ 2021-08-09 21:09 ` pinskia at gcc dot gnu.org
  2023-09-07  5:17 ` gayathri.gottumukkala.27 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Clang gets it way wrong (-1):
my operator new[](18446744073709551615)
caught unkown exception

ICC gets it right though:
std::bad_array_new_length


So I think GCC ordering is just wrong.

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

* [Bug c++/65350] [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements
  2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
                   ` (3 preceding siblings ...)
  2021-08-09 21:09 ` pinskia at gcc dot gnu.org
@ 2023-09-07  5:17 ` gayathri.gottumukkala.27 at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: gayathri.gottumukkala.27 at gmail dot com @ 2023-09-07  5:17 UTC (permalink / raw)
  To: gcc-bugs

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

Gayathri Gottumukkala <gayathri.gottumukkala.27 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gayathri.gottumukkala.27@gm
                   |                            |ail.com

--- Comment #4 from Gayathri Gottumukkala <gayathri.gottumukkala.27 at gmail dot com> ---
"cout" statement is executed before the exception is raised, hence two lines
are printed as output.

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

end of thread, other threads:[~2023-09-07  5:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-08 16:49 [Bug c/65350] New: [C++14] operator new[] should not be called if # of initializer elements exceeds # of elements kariya_mitsuru at hotmail dot com
2015-03-08 16:50 ` [Bug c/65350] " kariya_mitsuru at hotmail dot com
2015-03-13  3:51 ` [Bug c++/65350] " hubicka at gcc dot gnu.org
2015-03-13 10:15 ` redi at gcc dot gnu.org
2021-08-09 21:09 ` pinskia at gcc dot gnu.org
2023-09-07  5:17 ` gayathri.gottumukkala.27 at gmail dot com

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