From: Nathan Sidwell Date: Wed, 25 Apr 2001 08:31:19 +0000 (+0000) Subject: decl.c (grokdeclarator): Set context of namespace scope TYPE_DECLS. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6bda7a5e41bfca06a2cfdabbeb1c49948c8ab9eb;p=gcc.git decl.c (grokdeclarator): Set context of namespace scope TYPE_DECLS. cp: * decl.c (grokdeclarator): Set context of namespace scope TYPE_DECLS. testsuite: * g++.old-deja/g++.ns/type2.C: New test. From-SVN: r41533 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 618ba0d7b41..4ea7d43e835 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2001-04-25 Nathan Sidwell + + * decl.c (grokdeclarator): Set context of namespace scope + TYPE_DECLS. + 2001-04-24 Zack Weinberg * cp/optimize.c: Include hashtab.h. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 834e2dcd5da..ea37eb45c0d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11035,8 +11035,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) decl = build_lang_decl (TYPE_DECL, declarator, type); } else - decl = build_decl (TYPE_DECL, declarator, type); - + { + decl = build_decl (TYPE_DECL, declarator, type); + if (!current_function_decl) + DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); + } + /* If the user declares "typedef struct {...} foo" then the struct will have an anonymous name. Fill that name in now. Nothing can refer to it, so nothing needs know about the name diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 39abc4e4905..a0f0f2504d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-04-25 Nathan Sidwell + + * g++.old-deja/g++.ns/type2.C: New test. + 2001-04-24 Zack Weinberg * g++.old-deja/g++.other/perf1.C: New test. diff --git a/gcc/testsuite/g++.old-deja/g++.ns/type2.C b/gcc/testsuite/g++.old-deja/g++.ns/type2.C new file mode 100644 index 00000000000..d8407b151b4 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.ns/type2.C @@ -0,0 +1,19 @@ +// Build don't link: +// +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 11 April 2001 +// Origin:stephen.webb@cybersafe.com + +// Bug 2125. TYPE_DECLS never had their DECL_CONTEXT set, which +// confused forward references to classes. + +typedef void T; +namespace A { + class C; + typedef class C C; + typedef int T; + class C + { + T i; // got bogus error, found wrong T + }; +}