[C++ PATCH] Put builtin functions in std namespace
Kriang Lerdsuwanakij
lerdsuwa@scf.usc.edu
Wed Oct 11 15:51:00 GMT 2000
Hi
The following patch places builtin functions inside namespace std
when -fhonor-std. Only names that do not begin with double
underscore (like abs) are put there. Names like __builtin_constant_p
are already reserved. They remain in global namespace. Requiring
qualified name like std::__builtin_constant_p would break too many
programs and header files.
--Kriang
===============
2000-10-11 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* decl.c (init_decl_processing): Built std namespace node early.
(builtin_function): Put builtin function in std namespace
if the name does not begin with "__" and if flag_honor_std.
diff -cprN gcc-old/cp/decl.c gcc/cp/decl.c
*** gcc-old/cp/decl.c Wed Oct 11 14:35:13 2000
--- gcc/cp/decl.c Wed Oct 11 14:35:02 2000
*************** init_decl_processing ()
*** 6495,6500 ****
--- 6495,6507 ----
NAMESPACE_LEVEL (global_namespace) = global_binding_level;
declare_namespace_level ();
+ /* Make std namespace. */
+ std_node = build_decl (NAMESPACE_DECL,
+ flag_honor_std
+ ? get_identifier ("fake std") : std_identifier,
+ void_type_node);
+ pushdecl (std_node);
+
/* Define `int' and `char' first so that dbx will output them first. */
record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
record_builtin_type (RID_CHAR, "char", char_type_node);
*************** init_decl_processing ()
*** 6740,6751 ****
layout_type (vtbl_ptr_type_node);
record_builtin_type (RID_MAX, NULL_PTR, vtbl_ptr_type_node);
- std_node = build_decl (NAMESPACE_DECL,
- flag_honor_std
- ? get_identifier ("fake std") : std_identifier,
- void_type_node);
- pushdecl (std_node);
-
if (flag_new_abi)
{
push_namespace (get_identifier ("__cxxabiv1"));
--- 6747,6752 ----
*************** builtin_function (name, type, code, clas
*** 6921,6942 ****
const char *libname;
{
tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
DECL_BUILT_IN_CLASS (decl) = class;
DECL_FUNCTION_CODE (decl) = code;
my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
/* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
we cannot change DECL_ASSEMBLER_NAME until we have installed this
function in the namespace. */
pushdecl (decl);
if (libname)
DECL_ASSEMBLER_NAME (decl) = get_identifier (libname);
make_function_rtl (decl);
/* Warn if a function in the namespace for users
is used without an occasion to consider it declared. */
! if (name[0] != '_' || name[1] != '_')
DECL_ANTICIPATED (decl) = 1;
return decl;
--- 6922,6952 ----
const char *libname;
{
tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
+ int public_name = (name[0] != '_' || name[1] != '_');
+
DECL_BUILT_IN_CLASS (decl) = class;
DECL_FUNCTION_CODE (decl) = code;
my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
+ if (public_name && flag_honor_std)
+ push_namespace (get_identifier ("std"));
+
/* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
we cannot change DECL_ASSEMBLER_NAME until we have installed this
function in the namespace. */
pushdecl (decl);
+
+ if (public_name && flag_honor_std)
+ pop_namespace ();
+
if (libname)
DECL_ASSEMBLER_NAME (decl) = get_identifier (libname);
make_function_rtl (decl);
/* Warn if a function in the namespace for users
is used without an occasion to consider it declared. */
! if (public_name)
DECL_ANTICIPATED (decl) = 1;
return decl;
More information about the Gcc-patches
mailing list