+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
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:
+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.
--- /dev/null
+// 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" }
+};