re PR c++/11503 (segfault when instantiating template with ADDR_EXPR)
authorMark Mitchell <mark@codesourcery.com>
Mon, 14 Jul 2003 05:12:56 +0000 (05:12 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Mon, 14 Jul 2003 05:12:56 +0000 (05:12 +0000)
PR c++/11503
* g++.dg/template/anon1.C: New test.

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.

From-SVN: r69317

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/cp/search.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/anon1.C [new file with mode: 0644]

index c096405890f22135da27cf4a8dc16ba8273db9a9..6351dd6365cc3dbf72030eb17d594cd884193c6d 100644 (file)
@@ -1,5 +1,14 @@
 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.
+
+       * pt.c (reregister_specialization): Fix thinko in previous change.
+       
        * cp-tree.h (cp_id_kind): New type.
        (unqualified_name_lookup_error): Change prototype.
        (unqualified_fn_lookup_error): New function.
index bac2e0974a2112f30c60b34e0494280cd992b31c..56745901e9a0b8309432f40dd4c05602d81094ed 100644 (file)
@@ -6307,6 +6307,7 @@ build_self_reference (void)
   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);
index 24fd278c5371507568e2b15d0c0021557f270e97..32b791fb8054d34333e55eab7a00afde96fe2965 100644 (file)
@@ -97,6 +97,7 @@ struct diagnostic_context;
    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).
@@ -2751,16 +2752,20 @@ struct lang_decl GTY(())
   (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.  */
+   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.
index 37ec8688637aad6bcffcdb0298d4357fe6bc7789..ac032d13d953b84d910cd90d8c1072b24db6cfd9 100644 (file)
@@ -1002,7 +1002,7 @@ reregister_specialization (tree spec, tree tmpl, tree new_spec)
        if (!new_spec)
          *s = TREE_CHAIN (*s);
        else
-         TREE_VALUE (*s) == new_spec;
+         TREE_VALUE (*s) = new_spec;
        return 1;
       }
 
@@ -6200,6 +6200,8 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
        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;
index c2c158a691c3aac5fa7711ecf13fc2a02e4694a3..1161084980df26e573b3d8b218699c74b71071bc 100644 (file)
@@ -305,9 +305,7 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
            /* 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))
+           while (!DECL_SELF_REFERENCE_P (decl))
              decl = TREE_CHAIN (decl);
            while (ANON_AGGR_TYPE_P (t))
              t = TYPE_CONTEXT (t);
index 1dedd6563d4551f5761756f58b8434ee1f925a1a..e51dda898336556f3a40fe0ed712086ab679d8b7 100644 (file)
@@ -1,5 +1,8 @@
 2003-07-13  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/11503
+       * g++.dg/template/anon1.C: New test.
+
        PR c++/11493
        PR c++/11495
        * g++.dg/parse/template9.C: Likewise.
diff --git a/gcc/testsuite/g++.dg/template/anon1.C b/gcc/testsuite/g++.dg/template/anon1.C
new file mode 100644 (file)
index 0000000..ef73df6
--- /dev/null
@@ -0,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 ();