Commit a3d87771 by Mark Mitchell Committed by Mark Mitchell

re PR c++/11503 (segfault when instantiating template with ADDR_EXPR)

	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
parent b3445994
2003-07-13 Mark Mitchell <mark@codesourcery.com> 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. * cp-tree.h (cp_id_kind): New type.
(unqualified_name_lookup_error): Change prototype. (unqualified_name_lookup_error): Change prototype.
(unqualified_fn_lookup_error): New function. (unqualified_fn_lookup_error): New function.
......
...@@ -6307,6 +6307,7 @@ build_self_reference (void) ...@@ -6307,6 +6307,7 @@ build_self_reference (void)
DECL_NONLOCAL (value) = 1; DECL_NONLOCAL (value) = 1;
DECL_CONTEXT (value) = current_class_type; DECL_CONTEXT (value) = current_class_type;
DECL_ARTIFICIAL (value) = 1; DECL_ARTIFICIAL (value) = 1;
SET_DECL_SELF_REFERENCE_P (value);
if (processing_template_decl) if (processing_template_decl)
value = push_template_decl (value); value = push_template_decl (value);
......
...@@ -97,6 +97,7 @@ struct diagnostic_context; ...@@ -97,6 +97,7 @@ struct diagnostic_context;
3: DECL_IN_AGGR_P. 3: DECL_IN_AGGR_P.
4: DECL_C_BIT_FIELD (in a FIELD_DECL) 4: DECL_C_BIT_FIELD (in a FIELD_DECL)
DECL_VAR_MARKED_P (in a VAR_DECL) DECL_VAR_MARKED_P (in a VAR_DECL)
DECL_SELF_REFERENCE_P (in a TYPE_DECL)
5: DECL_INTERFACE_KNOWN. 5: DECL_INTERFACE_KNOWN.
6: DECL_THIS_STATIC (in VAR_DECL or FUNCTION_DECL). 6: DECL_THIS_STATIC (in VAR_DECL or FUNCTION_DECL).
7: DECL_DEAD_FOR_LOCAL (in VAR_DECL). 7: DECL_DEAD_FOR_LOCAL (in VAR_DECL).
...@@ -2751,16 +2752,20 @@ struct lang_decl GTY(()) ...@@ -2751,16 +2752,20 @@ struct lang_decl GTY(())
(TREE_CODE (NODE) == TYPE_DECL || DECL_CLASS_TEMPLATE_P (NODE)) (TREE_CODE (NODE) == TYPE_DECL || DECL_CLASS_TEMPLATE_P (NODE))
/* Nonzero if NODE is the typedef implicitly generated for a type when /* Nonzero if NODE is the typedef implicitly generated for a type when
the type is declared. (In C++, `struct S {};' is roughly equivalent the type is declared. In C++, `struct S {};' is roughly
to `struct S {}; typedef struct S S;' in C. This macro will hold equivalent to `struct S {}; typedef struct S S;' in C.
for the typedef indicated in this example. Note that in C++, there DECL_IMPLICIT_TYPEDEF_P will hold for the typedef indicated in this
is a second implicit typedef for each class, in the scope of `S' example. In C++, there is a second implicit typedef for each
itself, so that you can say `S::S'. This macro does *not* hold for class, in the scope of `S' itself, so that you can say `S::S'.
those typedefs. */ DECL_SELF_REFERENCE_P will hold for that second typedef. */
#define DECL_IMPLICIT_TYPEDEF_P(NODE) \ #define DECL_IMPLICIT_TYPEDEF_P(NODE) \
(TREE_CODE (NODE) == TYPE_DECL && DECL_LANG_FLAG_2 (NODE)) (TREE_CODE (NODE) == TYPE_DECL && DECL_LANG_FLAG_2 (NODE))
#define SET_DECL_IMPLICIT_TYPEDEF_P(NODE) \ #define SET_DECL_IMPLICIT_TYPEDEF_P(NODE) \
(DECL_LANG_FLAG_2 (NODE) = 1) (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 /* A `primary' template is one that has its own template header. A
member function of a class template is a template, but not primary. member function of a class template is a template, but not primary.
......
...@@ -1002,7 +1002,7 @@ reregister_specialization (tree spec, tree tmpl, tree new_spec) ...@@ -1002,7 +1002,7 @@ reregister_specialization (tree spec, tree tmpl, tree new_spec)
if (!new_spec) if (!new_spec)
*s = TREE_CHAIN (*s); *s = TREE_CHAIN (*s);
else else
TREE_VALUE (*s) == new_spec; TREE_VALUE (*s) = new_spec;
return 1; return 1;
} }
...@@ -6200,6 +6200,8 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain) ...@@ -6200,6 +6200,8 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
r = copy_decl (t); r = copy_decl (t);
if (TREE_CODE (r) == VAR_DECL) if (TREE_CODE (r) == VAR_DECL)
type = complete_type (type); type = complete_type (type);
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
TREE_TYPE (r) = type; TREE_TYPE (r) = type;
c_apply_type_quals_to_decl (cp_type_quals (type), r); c_apply_type_quals_to_decl (cp_type_quals (type), r);
DECL_CONTEXT (r) = ctx; DECL_CONTEXT (r) = ctx;
......
...@@ -305,9 +305,7 @@ lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr) ...@@ -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 /* Rather than inventing a public member, we use the implicit
public typedef created in the scope of every class. */ public typedef created in the scope of every class. */
decl = TYPE_FIELDS (base); decl = TYPE_FIELDS (base);
while (TREE_CODE (decl) != TYPE_DECL while (!DECL_SELF_REFERENCE_P (decl))
|| !DECL_ARTIFICIAL (decl)
|| DECL_NAME (decl) != constructor_name (base))
decl = TREE_CHAIN (decl); decl = TREE_CHAIN (decl);
while (ANON_AGGR_TYPE_P (t)) while (ANON_AGGR_TYPE_P (t))
t = TYPE_CONTEXT (t); t = TYPE_CONTEXT (t);
......
2003-07-13 Mark Mitchell <mark@codesourcery.com> 2003-07-13 Mark Mitchell <mark@codesourcery.com>
PR c++/11503
* g++.dg/template/anon1.C: New test.
PR c++/11493 PR c++/11493
PR c++/11495 PR c++/11495
* g++.dg/parse/template9.C: Likewise. * g++.dg/parse/template9.C: Likewise.
......
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 ();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment