re PR c++/31988 (new operator should not permit default first parameter)
cp/ 2007-10-26 Paolo Carlini <pcarlini@suse.de> PR c++/31988 * decl2.c (coerce_new_type): Do not allow a default argument for the first parameter. testsuite/ 2007-10-26 Paolo Carlini <pcarlini@suse.de> PR c++/31988 * g++.dg/init/new25.C: New. From-SVN: r129657
This commit is contained in:
parent
2b536806af
commit
07021f8c63
|
@ -1,3 +1,9 @@
|
|||
2007-10-26 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR c++/31988
|
||||
* decl2.c (coerce_new_type): Do not allow a default argument for
|
||||
the first parameter.
|
||||
|
||||
2007-10-26 Douglas Gregor <doug.gregor@gmail.com>
|
||||
|
||||
PR c++/33839
|
||||
|
|
|
@ -1251,15 +1251,33 @@ coerce_new_type (tree type)
|
|||
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))
|
||||
if (args && args != void_list_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);
|
||||
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:
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2007-10-26 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR c++/31988
|
||||
* g++.dg/init/new25.C: New.
|
||||
|
||||
2007-10-26 Douglas Gregor <doug.gregor@gmail.com>
|
||||
|
||||
* g++.dg/cpp0x/pr33839.C: New.
|
||||
|
|
|
@ -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" }
|
||||
};
|
Loading…
Reference in New Issue