diff options
author | Paolo Carlini <pcarlini@suse.de> | 2007-10-26 18:32:41 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2007-10-26 18:32:41 +0000 |
commit | 07021f8c632eb69b3f4082acd8af08a484fcdc21 (patch) | |
tree | a4e9a38ac896b6bfc8e16bfbf28f3e21214b2405 /gcc/cp/decl2.c | |
parent | 2b536806afcb297162fdc44e04cbf6f2c21e66aa (diff) | |
download | gcc-07021f8c632eb69b3f4082acd8af08a484fcdc21.zip gcc-07021f8c632eb69b3f4082acd8af08a484fcdc21.tar.gz gcc-07021f8c632eb69b3f4082acd8af08a484fcdc21.tar.bz2 |
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
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r-- | gcc/cp/decl2.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index ce5e528..0a97834 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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: |