This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 11503
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 13 Jul 2003 22:25:41 -0700
- Subject: C++ PATCH: PR 11503
- Reply-to: mark at codesourcery dot com
This patch fixes PR 11503, a recently-introduced ICE. (I caused this
new problem while fixing a long-standing regression in static_cast.)
Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2003-07-13 Mark Mitchell <mark@codesourcery.com>
PR c++/11503
* g++.dg/template/anon1.C: New test.
2003-07-13 Mark Mitchell <mark@codesourcery.com>
PR c++/11503
* cp-tree.h (DECL_SELF_REFERENCE_P): New macro.
(SET_DECL_SELF_REFERENCE_P): Likewise.
* class.c (build_self_reference): Use SET_DECL_SELF_REFERENCE_P.
* pt.c (tsubst_decl): Copy it.
* search.c (lookup_base): Use DECL_SELF_REFERENCE_P.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.551
diff -c -5 -p -r1.551 class.c
*** cp/class.c 10 Jul 2003 09:02:03 -0000 1.551
--- cp/class.c 14 Jul 2003 05:08:12 -0000
*************** build_self_reference (void)
*** 6305,6314 ****
--- 6305,6315 ----
tree saved_cas;
DECL_NONLOCAL (value) = 1;
DECL_CONTEXT (value) = current_class_type;
DECL_ARTIFICIAL (value) = 1;
+ SET_DECL_SELF_REFERENCE_P (value);
if (processing_template_decl)
value = push_template_decl (value);
saved_cas = current_access_specifier;
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.874
diff -c -5 -p -r1.874 cp-tree.h
*** cp/cp-tree.h 14 Jul 2003 03:04:24 -0000 1.874
--- cp/cp-tree.h 14 Jul 2003 05:08:19 -0000
*************** struct diagnostic_context;
*** 95,104 ****
--- 95,105 ----
2: DECL_THIS_EXTERN (in VAR_DECL or FUNCTION_DECL).
DECL_IMPLICIT_TYPEDEF_P (in a TYPE_DECL)
3: DECL_IN_AGGR_P.
4: DECL_C_BIT_FIELD (in a FIELD_DECL)
DECL_VAR_MARKED_P (in a VAR_DECL)
+ DECL_SELF_REFERENCE_P (in a TYPE_DECL)
5: DECL_INTERFACE_KNOWN.
6: DECL_THIS_STATIC (in VAR_DECL or FUNCTION_DECL).
7: DECL_DEAD_FOR_LOCAL (in VAR_DECL).
DECL_THUNK_P (in a member FUNCTION_DECL)
*************** struct lang_decl GTY(())
*** 2749,2768 ****
/* Nonzero if NODE which declares a type. */
#define DECL_DECLARES_TYPE_P(NODE) \
(TREE_CODE (NODE) == TYPE_DECL || DECL_CLASS_TEMPLATE_P (NODE))
/* Nonzero if NODE is the typedef implicitly generated for a type when
! the type is declared. (In C++, `struct S {};' is roughly equivalent
! to `struct S {}; typedef struct S S;' in C. This macro will hold
! for the typedef indicated in this example. Note that in C++, there
! is a second implicit typedef for each class, in the scope of `S'
! itself, so that you can say `S::S'. This macro does *not* hold for
! those typedefs. */
#define DECL_IMPLICIT_TYPEDEF_P(NODE) \
(TREE_CODE (NODE) == TYPE_DECL && DECL_LANG_FLAG_2 (NODE))
#define SET_DECL_IMPLICIT_TYPEDEF_P(NODE) \
(DECL_LANG_FLAG_2 (NODE) = 1)
/* A `primary' template is one that has its own template header. A
member function of a class template is a template, but not primary.
A member template is primary. Friend templates are primary, too. */
--- 2750,2773 ----
/* Nonzero if NODE which declares a type. */
#define DECL_DECLARES_TYPE_P(NODE) \
(TREE_CODE (NODE) == TYPE_DECL || DECL_CLASS_TEMPLATE_P (NODE))
/* Nonzero if NODE is the typedef implicitly generated for a type when
! the type is declared. In C++, `struct S {};' is roughly
! equivalent to `struct S {}; typedef struct S S;' in C.
! DECL_IMPLICIT_TYPEDEF_P will hold for the typedef indicated in this
! example. In C++, there is a second implicit typedef for each
! class, in the scope of `S' itself, so that you can say `S::S'.
! DECL_SELF_REFERENCE_P will hold for that second typedef. */
#define DECL_IMPLICIT_TYPEDEF_P(NODE) \
(TREE_CODE (NODE) == TYPE_DECL && DECL_LANG_FLAG_2 (NODE))
#define SET_DECL_IMPLICIT_TYPEDEF_P(NODE) \
(DECL_LANG_FLAG_2 (NODE) = 1)
+ #define DECL_SELF_REFERENCE_P(NODE) \
+ (TREE_CODE (NODE) == TYPE_DECL && DECL_LANG_FLAG_4 (NODE))
+ #define SET_DECL_SELF_REFERENCE_P(NODE) \
+ (DECL_LANG_FLAG_4 (NODE) = 1)
/* A `primary' template is one that has its own template header. A
member function of a class template is a template, but not primary.
A member template is primary. Friend templates are primary, too. */
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.722
diff -c -5 -p -r1.722 pt.c
*** cp/pt.c 14 Jul 2003 03:04:24 -0000 1.722
--- cp/pt.c 14 Jul 2003 05:08:27 -0000
*************** tsubst_decl (tree t, tree args, tree typ
*** 6198,6207 ****
--- 6198,6209 ----
}
r = copy_decl (t);
if (TREE_CODE (r) == VAR_DECL)
type = complete_type (type);
+ else if (DECL_SELF_REFERENCE_P (t))
+ SET_DECL_SELF_REFERENCE_P (r);
TREE_TYPE (r) = type;
c_apply_type_quals_to_decl (cp_type_quals (type), r);
DECL_CONTEXT (r) = ctx;
/* Clear out the mangled name and RTL for the instantiation. */
SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
Index: cp/search.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/search.c,v
retrieving revision 1.274
diff -c -5 -p -r1.274 search.c
*** cp/search.c 9 Jul 2003 23:06:39 -0000 1.274
--- cp/search.c 14 Jul 2003 05:08:28 -0000
*************** lookup_base (tree t, tree base, base_acc
*** 303,315 ****
A base class is said to be accessible if an invented public
member of the base class is accessible. */
/* Rather than inventing a public member, we use the implicit
public typedef created in the scope of every class. */
decl = TYPE_FIELDS (base);
! while (TREE_CODE (decl) != TYPE_DECL
! || !DECL_ARTIFICIAL (decl)
! || DECL_NAME (decl) != constructor_name (base))
decl = TREE_CHAIN (decl);
while (ANON_AGGR_TYPE_P (t))
t = TYPE_CONTEXT (t);
if (!accessible_p (t, decl))
{
--- 303,313 ----
A base class is said to be accessible if an invented public
member of the base class is accessible. */
/* Rather than inventing a public member, we use the implicit
public typedef created in the scope of every class. */
decl = TYPE_FIELDS (base);
! while (!DECL_SELF_REFERENCE_P (decl))
decl = TREE_CHAIN (decl);
while (ANON_AGGR_TYPE_P (t))
t = TYPE_CONTEXT (t);
if (!accessible_p (t, decl))
{
Index: testsuite/g++.dg/template/anon1.C
===================================================================
RCS file: testsuite/g++.dg/template/anon1.C
diff -N testsuite/g++.dg/template/anon1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/anon1.C 14 Jul 2003 05:08:31 -0000
***************
*** 0 ****
--- 1,21 ----
+ struct x {
+ int foo () {}
+ };
+
+ template <class T>
+ struct vector {
+ T& bar () {}
+ };
+
+ template <class T>
+ struct y {
+ typedef struct {
+ x t;
+ } s;
+
+ vector<s> array;
+
+ int foo ()
+ { return array.bar().t.foo(); }
+ };
+ int i = y<x>().foo ();