PATCH: Avoid push_to_top_level
Giovanni Bajo
giovannibajo@libero.it
Mon Jul 12 05:31:00 GMT 2004
Mark Mitchell wrote:
> I mistakenly assumed that we diagnosed that case; I knew it was
> invalid, and therefore assumed it could not occur.
Actually, why doesn't the standard disallow also to declare allocator functions
at local scope, if they're going to be ignored anyway? Maybe this is worth a
DR.
> (I should also mention that I think that Nathan's reading, while
> plausible, is not what was actually intended. I've asked the EDG
> folks; their front end implements the rules as they were in G++
> before your patch.)
Comeau online actually behaves exactly like G++ after my patch: try it with the
new1.C testcase.
> In any case, we should diagnose the invalid namespace-scope
> declaration; that's the easiest way to fix the problem I caused.
>
> It's my responsibility; by our current reading of the standard I've
> introduced a regression. However, if you are willing to fix it, I
> would be most grateful! Please let me know; if you don't want
> to do it, I will take care of it.
Does this look ok? Testing in progress on i686-pc-linux-gnu.
Giovanni Bajo
cp/
* decl.c (grok_op_properties): Reject [de-]allocation functions
declared in a namespace, or declared as static.
testsuite/
* g++.dg/lookup/new2.C: New test.
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1228
diff -c -3 -p -r1.1228 decl.c
*** decl.c 26 Jun 2004 21:11:17 -0000 1.1228
--- decl.c 12 Jul 2004 02:55:01 -0000
*************** grok_op_properties (tree decl, int frien
*** 8558,8563 ****
--- 8554,8578 ----
}
}
+ /* [basic.std.dynamic.allocation]/1:
+
+ A program is ill-formed if an allocation function is declared
+ in a namespace scope other than global scope or declared static
+ in global scope.
+
+ The same also holds true for deallocation functions. */
+ if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR
+ || operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
+ {
+ if (DECL_NAMESPACE_SCOPE_P (decl))
+ {
+ if (CP_DECL_CONTEXT (decl) != global_namespace)
+ error ("`%D' may not be declared within a namespace", decl);
+ else if (!TREE_PUBLIC (decl))
+ error ("`%D' may not be declared as static", decl);
+ }
+ }
+
if (operator_code == NEW_EXPR || operator_code == VEC_NEW_EXPR)
TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
else if (operator_code == DELETE_EXPR || operator_code == VEC_DELETE_EXPR)
// { dg-do compile }
// Reject [de-]allocation functions declared in a namespace, or
// declared as static.
namespace A {
void* operator new(unsigned s, int* p); // { dg-error "namespace" }
void operator delete(void*); // { dg-error "namespace" }
}
static void* operator new(unsigned s, int* p); // { dg-error "static" }
static void operator delete(void*); // { dg-error "static" }
More information about the Gcc-patches
mailing list