From: Mark Mitchell Date: Thu, 27 Aug 1998 00:14:27 +0000 (+0000) Subject: decl.c (build_enumerator): Set DECL_CONTEXT for the CONST_DECLs. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e8bd800e45b432c80294945265888aac20add1ff;p=gcc.git decl.c (build_enumerator): Set DECL_CONTEXT for the CONST_DECLs. * decl.c (build_enumerator): Set DECL_CONTEXT for the CONST_DECLs. From-SVN: r22014 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 366f352c4ca..636fc12c76c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +1998-08-27 Mark Mitchell + + * decl.c (build_enumerator): Set DECL_CONTEXT for the + CONST_DECLs. + 1998-08-26 Mark Mitchell * cp-tree.h (finish_enum): Change prototype. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 995207d7cc3..ad52979fb8e 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11994,6 +11994,7 @@ build_enumerator (name, value) tree name, value; { tree decl, result; + tree context; /* Remove no-op casts from the value. */ if (value) @@ -12042,30 +12043,31 @@ build_enumerator (name, value) value = copy_node (value); /* C++ associates enums with global, function, or class declarations. */ - - decl = current_scope (); - if (decl && decl == current_class_type) - { - /* This enum declaration is local to the class, so we must put - it in that class's list of decls. */ - decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); - DECL_INITIAL (decl) = value; - TREE_READONLY (decl) = 1; - pushdecl_class_level (decl); - TREE_CHAIN (decl) = current_local_enum; - current_local_enum = decl; - } - else - { - /* It's a global enum, or it's local to a function. (Note local to - a function could mean local to a class method. */ - decl = build_decl (CONST_DECL, name, integer_type_node); - DECL_INITIAL (decl) = value; - TREE_READONLY (decl) = 1; - - pushdecl (decl); - GNU_xref_decl (current_function_decl, decl); - } + + context = current_scope (); + if (context && context == current_class_type) + /* This enum declaration is local to the class. */ + decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); + else + /* It's a global enum, or it's local to a function. (Note local to + a function could mean local to a class method. */ + decl = build_decl (CONST_DECL, name, integer_type_node); + + DECL_CONTEXT (decl) = FROB_CONTEXT (context); + DECL_INITIAL (decl) = value; + TREE_READONLY (decl) = 1; + + if (context && context == current_class_type) + { + pushdecl_class_level (decl); + TREE_CHAIN (decl) = current_local_enum; + current_local_enum = decl; + } + else + { + pushdecl (decl); + GNU_xref_decl (current_function_decl, decl); + } if (! processing_template_decl) { diff --git a/gcc/testsuite/g++.old-deja/g++.pt/enum9.C b/gcc/testsuite/g++.old-deja/g++.pt/enum9.C new file mode 100644 index 00000000000..96aeaa689cc --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/enum9.C @@ -0,0 +1,13 @@ +// Build don't link: + +template +class _Format_cache +{ +public: + enum { + _S_digits, _S_digits_end = _S_digits+10, + _S_xdigits = _S_digits_end, + }; +}; + +template class _Format_cache;