This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ Patch] PR 31988
Mark Mitchell wrote:
> Paolo Carlini wrote:
>
>> Good point. Unfortunately, the above, as-is, gets the logic slightly
>> wrong.
>>
> :-( Sorry about that.
>
> Let's factor the duplicate pedwarn out of your version by moving it
> below the "if", and then saying:
>
> if (e == 2)
> pedwarn (...);
>
> OK with that change.
>
As committed. Thanks,
Paolo.
//////////////////
Index: testsuite/g++.dg/init/new25.C
===================================================================
*** testsuite/g++.dg/init/new25.C (revision 0)
--- testsuite/g++.dg/init/new25.C (revision 0)
***************
*** 0 ****
--- 1,29 ----
+ // PR c++/31988
+ #include <new>
+
+ class C
+ {
+ public:
+ void* operator new(std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" }
+ void* operator new[](std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" }
+ void* operator new(std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" }
+ void* operator new[](std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" }
+ };
+
+ class D
+ {
+ public:
+ void* operator new(std::size_t,
+ const std::nothrow_t& = std::nothrow_t()) throw();
+ void* operator new[](std::size_t,
+ const std::nothrow_t& = std::nothrow_t()) throw();
+ };
+
+ class E
+ {
+ public:
+ void* operator new(std::size_t = 0,
+ const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" }
+ void* operator new[](std::size_t = 0,
+ const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" }
+ };
Index: cp/decl2.c
===================================================================
*** cp/decl2.c (revision 129653)
--- cp/decl2.c (working copy)
*************** coerce_new_type (tree type)
*** 1251,1265 ****
error ("%<operator new%> must return type %qT", ptr_type_node);
}
! if (!args || args == void_list_node
! || !same_type_p (TREE_VALUE (args), size_type_node))
{
! e = 2;
! if (args && args != void_list_node)
! args = TREE_CHAIN (args);
! pedwarn ("%<operator new%> takes type %<size_t%> (%qT) "
! "as first parameter", size_type_node);
}
switch (e)
{
case 2:
--- 1251,1283 ----
error ("%<operator new%> must return type %qT", ptr_type_node);
}
! if (args && args != void_list_node)
{
! if (TREE_PURPOSE (args))
! {
! /* [basic.stc.dynamic.allocation]
!
! The first parameter shall not have an associated default
! argument. */
! error ("the first parameter of %<operator new%> cannot "
! "have a default argument");
! /* Throw away the default argument. */
! TREE_PURPOSE (args) = NULL_TREE;
! }
!
! if (!same_type_p (TREE_VALUE (args), size_type_node))
! {
! e = 2;
! args = TREE_CHAIN (args);
! }
}
+ else
+ e = 2;
+
+ if (e == 2)
+ pedwarn ("%<operator new%> takes type %<size_t%> (%qT) "
+ "as first parameter", size_type_node);
+
switch (e)
{
case 2: