1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987-2020 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* High-level class interface. */
26 #include "coretypes.h"
30 #include "spellcheck-tree.h"
31 #include "stringpool.h"
34 static int is_subobject_of_p (tree
, tree
);
35 static tree
dfs_lookup_base (tree
, void *);
36 static tree
dfs_dcast_hint_pre (tree
, void *);
37 static tree
dfs_dcast_hint_post (tree
, void *);
38 static tree
dfs_debug_mark (tree
, void *);
39 static int check_hidden_convs (tree
, int, int, tree
, tree
, tree
);
40 static tree
split_conversions (tree
, tree
, tree
, tree
);
41 static int lookup_conversions_r (tree
, int, int, tree
, tree
, tree
*);
42 static int look_for_overrides_r (tree
, tree
);
43 static tree
lookup_field_r (tree
, void *);
44 static tree
dfs_accessible_post (tree
, void *);
45 static tree
dfs_walk_once_accessible (tree
, bool,
46 tree (*pre_fn
) (tree
, void *),
47 tree (*post_fn
) (tree
, void *),
49 static tree
dfs_access_in_type (tree
, void *);
50 static access_kind
access_in_type (tree
, tree
);
51 static tree
dfs_get_pure_virtuals (tree
, void *);
54 /* Data for lookup_base and its workers. */
56 struct lookup_base_data_s
58 tree t
; /* type being searched. */
59 tree base
; /* The base type we're looking for. */
60 tree binfo
; /* Found binfo. */
61 bool via_virtual
; /* Found via a virtual path. */
62 bool ambiguous
; /* Found multiply ambiguous */
63 bool repeated_base
; /* Whether there are repeated bases in the
65 bool want_any
; /* Whether we want any matching binfo. */
68 /* Worker function for lookup_base. See if we've found the desired
69 base and update DATA_ (a pointer to LOOKUP_BASE_DATA_S). */
72 dfs_lookup_base (tree binfo
, void *data_
)
74 struct lookup_base_data_s
*data
= (struct lookup_base_data_s
*) data_
;
76 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), data
->base
))
82 = binfo_via_virtual (data
->binfo
, data
->t
) != NULL_TREE
;
84 if (!data
->repeated_base
)
85 /* If there are no repeated bases, we can stop now. */
88 if (data
->want_any
&& !data
->via_virtual
)
89 /* If this is a non-virtual base, then we can't do
93 return dfs_skip_bases
;
97 gcc_assert (binfo
!= data
->binfo
);
99 /* We've found more than one matching binfo. */
102 /* This is immediately ambiguous. */
103 data
->binfo
= NULL_TREE
;
104 data
->ambiguous
= true;
105 return error_mark_node
;
108 /* Prefer one via a non-virtual path. */
109 if (!binfo_via_virtual (binfo
, data
->t
))
112 data
->via_virtual
= false;
116 /* There must be repeated bases, otherwise we'd have stopped
117 on the first base we found. */
118 return dfs_skip_bases
;
125 /* Returns true if type BASE is accessible in T. (BASE is known to be
126 a (possibly non-proper) base class of T.) If CONSIDER_LOCAL_P is
127 true, consider any special access of the current scope, or access
128 bestowed by friendship. */
131 accessible_base_p (tree t
, tree base
, bool consider_local_p
)
135 /* [class.access.base]
137 A base class is said to be accessible if an invented public
138 member of the base class is accessible.
140 If BASE is a non-proper base, this condition is trivially
142 if (same_type_p (t
, base
))
144 /* Rather than inventing a public member, we use the implicit
145 public typedef created in the scope of every class. */
146 decl
= TYPE_FIELDS (base
);
147 while (!DECL_SELF_REFERENCE_P (decl
))
148 decl
= DECL_CHAIN (decl
);
149 while (ANON_AGGR_TYPE_P (t
))
150 t
= TYPE_CONTEXT (t
);
151 return accessible_p (t
, decl
, consider_local_p
);
154 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
155 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
156 non-NULL, fill with information about what kind of base we
159 If the base is inaccessible, or ambiguous, then error_mark_node is
160 returned. If the tf_error bit of COMPLAIN is not set, no error
164 lookup_base (tree t
, tree base
, base_access access
,
165 base_kind
*kind_ptr
, tsubst_flags_t complain
)
171 /* "Nothing" is definitely not derived from Base. */
175 *kind_ptr
= bk_not_base
;
179 if (t
== error_mark_node
|| base
== error_mark_node
)
182 *kind_ptr
= bk_not_base
;
183 return error_mark_node
;
185 gcc_assert (TYPE_P (base
));
194 t
= complete_type (TYPE_MAIN_VARIANT (t
));
195 if (dependent_type_p (t
))
196 if (tree open
= currently_open_class (t
))
198 t_binfo
= TYPE_BINFO (t
);
201 base
= TYPE_MAIN_VARIANT (base
);
203 /* If BASE is incomplete, it can't be a base of T--and instantiating it
204 might cause an error. */
205 if (t_binfo
&& CLASS_TYPE_P (base
) && COMPLETE_OR_OPEN_TYPE_P (base
))
207 struct lookup_base_data_s data
;
211 data
.binfo
= NULL_TREE
;
212 data
.ambiguous
= data
.via_virtual
= false;
213 data
.repeated_base
= CLASSTYPE_REPEATED_BASE_P (t
);
214 data
.want_any
= access
== ba_any
;
216 dfs_walk_once (t_binfo
, dfs_lookup_base
, NULL
, &data
);
220 bk
= data
.ambiguous
? bk_ambig
: bk_not_base
;
221 else if (binfo
== t_binfo
)
223 else if (data
.via_virtual
)
234 /* Check that the base is unambiguous and accessible. */
235 if (access
!= ba_any
)
242 if (complain
& tf_error
)
243 error ("%qT is an ambiguous base of %qT", base
, t
);
244 binfo
= error_mark_node
;
248 if ((access
& ba_check_bit
)
249 /* If BASE is incomplete, then BASE and TYPE are probably
250 the same, in which case BASE is accessible. If they
251 are not the same, then TYPE is invalid. In that case,
252 there's no need to issue another error here, and
253 there's no implicit typedef to use in the code that
254 follows, so we skip the check. */
255 && COMPLETE_TYPE_P (base
)
256 && !accessible_base_p (t
, base
, !(access
& ba_ignore_scope
)))
258 if (complain
& tf_error
)
259 error ("%qT is an inaccessible base of %qT", base
, t
);
260 binfo
= error_mark_node
;
261 bk
= bk_inaccessible
;
272 /* Data for dcast_base_hint walker. */
276 tree subtype
; /* The base type we're looking for. */
277 int virt_depth
; /* Number of virtual bases encountered from most
279 tree offset
; /* Best hint offset discovered so far. */
280 bool repeated_base
; /* Whether there are repeated bases in the
284 /* Worker for dcast_base_hint. Search for the base type being cast
288 dfs_dcast_hint_pre (tree binfo
, void *data_
)
290 struct dcast_data_s
*data
= (struct dcast_data_s
*) data_
;
292 if (BINFO_VIRTUAL_P (binfo
))
295 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), data
->subtype
))
297 if (data
->virt_depth
)
299 data
->offset
= ssize_int (-1);
303 data
->offset
= ssize_int (-3);
305 data
->offset
= BINFO_OFFSET (binfo
);
307 return data
->repeated_base
? dfs_skip_bases
: data
->offset
;
313 /* Worker for dcast_base_hint. Track the virtual depth. */
316 dfs_dcast_hint_post (tree binfo
, void *data_
)
318 struct dcast_data_s
*data
= (struct dcast_data_s
*) data_
;
320 if (BINFO_VIRTUAL_P (binfo
))
326 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
327 started from is related to the required TARGET type, in order to optimize
328 the inheritance graph search. This information is independent of the
329 current context, and ignores private paths, hence get_base_distance is
330 inappropriate. Return a TREE specifying the base offset, BOFF.
331 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
332 and there are no public virtual SUBTYPE bases.
333 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
334 BOFF == -2, SUBTYPE is not a public base.
335 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
338 dcast_base_hint (tree subtype
, tree target
)
340 struct dcast_data_s data
;
342 data
.subtype
= subtype
;
344 data
.offset
= NULL_TREE
;
345 data
.repeated_base
= CLASSTYPE_REPEATED_BASE_P (target
);
347 dfs_walk_once_accessible (TYPE_BINFO (target
), /*friends=*/false,
348 dfs_dcast_hint_pre
, dfs_dcast_hint_post
, &data
);
349 return data
.offset
? data
.offset
: ssize_int (-2);
352 /* Search for a member with name NAME in a multiple inheritance
353 lattice specified by TYPE. If it does not exist, return NULL_TREE.
354 If the member is ambiguously referenced, return `error_mark_node'.
355 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
356 true, type declarations are preferred. */
358 /* Return the FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, or
359 NAMESPACE_DECL corresponding to the innermost non-block scope. */
364 /* There are a number of cases we need to be aware of here:
365 current_class_type current_function_decl
372 Those last two make life interesting. If we're in a function which is
373 itself inside a class, we need decls to go into the fn's decls (our
374 second case below). But if we're in a class and the class itself is
375 inside a function, we need decls to go into the decls for the class. To
376 achieve this last goal, we must see if, when both current_class_ptr and
377 current_function_decl are set, the class was declared inside that
378 function. If so, we know to put the decls into the class's scope. */
379 if (current_function_decl
&& current_class_type
380 && ((DECL_FUNCTION_MEMBER_P (current_function_decl
)
381 && same_type_p (DECL_CONTEXT (current_function_decl
),
383 || (DECL_FRIEND_CONTEXT (current_function_decl
)
384 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl
),
385 current_class_type
))))
386 return current_function_decl
;
388 if (current_class_type
)
389 return current_class_type
;
391 if (current_function_decl
)
392 return current_function_decl
;
394 return current_namespace
;
397 /* Returns nonzero if we are currently in a function scope. Note
398 that this function returns zero if we are within a local class, but
399 not within a member function body of the local class. */
402 at_function_scope_p (void)
404 tree cs
= current_scope ();
405 /* Also check cfun to make sure that we're really compiling
406 this function (as opposed to having set current_function_decl
407 for access checking or some such). */
408 return (cs
&& TREE_CODE (cs
) == FUNCTION_DECL
409 && cfun
&& cfun
->decl
== current_function_decl
);
412 /* Returns true if the innermost active scope is a class scope. */
415 at_class_scope_p (void)
417 tree cs
= current_scope ();
418 return cs
&& TYPE_P (cs
);
421 /* Returns true if the innermost active scope is a namespace scope. */
424 at_namespace_scope_p (void)
426 tree cs
= current_scope ();
427 return cs
&& TREE_CODE (cs
) == NAMESPACE_DECL
;
430 /* Return the scope of DECL, as appropriate when doing name-lookup. */
433 context_for_name_lookup (tree decl
)
437 For the purposes of name lookup, after the anonymous union
438 definition, the members of the anonymous union are considered to
439 have been defined in the scope in which the anonymous union is
441 tree context
= DECL_CONTEXT (decl
);
443 while (context
&& TYPE_P (context
)
444 && (ANON_AGGR_TYPE_P (context
) || UNSCOPED_ENUM_P (context
)))
445 context
= TYPE_CONTEXT (context
);
447 context
= global_namespace
;
452 /* Returns true iff DECL is declared in TYPE. */
455 member_declared_in_type (tree decl
, tree type
)
457 /* A normal declaration obviously counts. */
458 if (context_for_name_lookup (decl
) == type
)
460 /* So does a using or access declaration. */
461 if (DECL_LANG_SPECIFIC (decl
) && !DECL_DISCRIMINATOR_P (decl
)
462 && purpose_member (type
, DECL_ACCESS (decl
)))
467 /* The accessibility routines use BINFO_ACCESS for scratch space
468 during the computation of the accessibility of some declaration. */
470 /* Avoid walking up past a declaration of the member. */
473 dfs_access_in_type_pre (tree binfo
, void *data
)
475 tree decl
= (tree
) data
;
476 tree type
= BINFO_TYPE (binfo
);
477 if (member_declared_in_type (decl
, type
))
478 return dfs_skip_bases
;
482 #define BINFO_ACCESS(NODE) \
483 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
485 /* Set the access associated with NODE to ACCESS. */
487 #define SET_BINFO_ACCESS(NODE, ACCESS) \
488 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
489 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
491 /* Called from access_in_type via dfs_walk. Calculate the access to
492 DATA (which is really a DECL) in BINFO. */
495 dfs_access_in_type (tree binfo
, void *data
)
497 tree decl
= (tree
) data
;
498 tree type
= BINFO_TYPE (binfo
);
499 access_kind access
= ak_none
;
501 if (context_for_name_lookup (decl
) == type
)
503 /* If we have descended to the scope of DECL, just note the
504 appropriate access. */
505 if (TREE_PRIVATE (decl
))
507 else if (TREE_PROTECTED (decl
))
508 access
= ak_protected
;
514 /* First, check for an access-declaration that gives us more
515 access to the DECL. */
516 if (DECL_LANG_SPECIFIC (decl
) && !DECL_DISCRIMINATOR_P (decl
))
518 tree decl_access
= purpose_member (type
, DECL_ACCESS (decl
));
522 decl_access
= TREE_VALUE (decl_access
);
524 if (decl_access
== access_public_node
)
526 else if (decl_access
== access_protected_node
)
527 access
= ak_protected
;
528 else if (decl_access
== access_private_node
)
539 vec
<tree
, va_gc
> *accesses
;
541 /* Otherwise, scan our baseclasses, and pick the most favorable
543 accesses
= BINFO_BASE_ACCESSES (binfo
);
544 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
546 tree base_access
= (*accesses
)[i
];
547 access_kind base_access_now
= BINFO_ACCESS (base_binfo
);
549 if (base_access_now
== ak_none
|| base_access_now
== ak_private
)
550 /* If it was not accessible in the base, or only
551 accessible as a private member, we can't access it
553 base_access_now
= ak_none
;
554 else if (base_access
== access_protected_node
)
555 /* Public and protected members in the base become
557 base_access_now
= ak_protected
;
558 else if (base_access
== access_private_node
)
559 /* Public and protected members in the base become
561 base_access_now
= ak_private
;
563 /* See if the new access, via this base, gives more
564 access than our previous best access. */
565 if (base_access_now
!= ak_none
566 && (access
== ak_none
|| base_access_now
< access
))
568 access
= base_access_now
;
570 /* If the new access is public, we can't do better. */
571 if (access
== ak_public
)
578 /* Note the access to DECL in TYPE. */
579 SET_BINFO_ACCESS (binfo
, access
);
584 /* Return the access to DECL in TYPE. */
587 access_in_type (tree type
, tree decl
)
589 tree binfo
= TYPE_BINFO (type
);
591 /* We must take into account
595 If a name can be reached by several paths through a multiple
596 inheritance graph, the access is that of the path that gives
599 The algorithm we use is to make a post-order depth-first traversal
600 of the base-class hierarchy. As we come up the tree, we annotate
601 each node with the most lenient access. */
602 dfs_walk_once (binfo
, dfs_access_in_type_pre
, dfs_access_in_type
, decl
);
604 return BINFO_ACCESS (binfo
);
607 /* Returns nonzero if it is OK to access DECL named in TYPE through an object
608 of OTYPE in the context of DERIVED. */
611 protected_accessible_p (tree decl
, tree derived
, tree type
, tree otype
)
613 /* We're checking this clause from [class.access.base]
615 m as a member of N is protected, and the reference occurs in a
616 member or friend of class N, or in a member or friend of a
617 class P derived from N, where m as a member of P is public, private
620 Here DERIVED is a possible P, DECL is m and TYPE is N. */
622 /* If DERIVED isn't derived from N, then it can't be a P. */
623 if (!DERIVED_FROM_P (type
, derived
))
626 /* DECL_NONSTATIC_MEMBER_P won't work for USING_DECLs. */
627 decl
= strip_using_decl (decl
);
628 /* We don't expect or support dependent decls. */
629 gcc_assert (TREE_CODE (decl
) != USING_DECL
);
633 When a friend or a member function of a derived class references
634 a protected non-static member of a base class, an access check
635 applies in addition to those described earlier in clause
636 _class.access_) Except when forming a pointer to member
637 (_expr.unary.op_), the access must be through a pointer to,
638 reference to, or object of the derived class itself (or any class
639 derived from that class) (_expr.ref_). If the access is to form
640 a pointer to member, the nested-name-specifier shall name the
641 derived class (or any class derived from that class). */
642 if (DECL_NONSTATIC_MEMBER_P (decl
)
643 && !DERIVED_FROM_P (derived
, otype
))
649 /* Returns nonzero if SCOPE is a type or a friend of a type which would be able
650 to access DECL through TYPE. OTYPE is the type of the object. */
653 friend_accessible_p (tree scope
, tree decl
, tree type
, tree otype
)
655 /* We're checking this clause from [class.access.base]
657 m as a member of N is protected, and the reference occurs in a
658 member or friend of class N, or in a member or friend of a
659 class P derived from N, where m as a member of P is public, private
662 Here DECL is m and TYPE is N. SCOPE is the current context,
663 and we check all its possible Ps. */
664 tree befriending_classes
;
670 if (is_global_friend (scope
))
673 /* Is SCOPE itself a suitable P? */
674 if (TYPE_P (scope
) && protected_accessible_p (decl
, scope
, type
, otype
))
677 if (DECL_DECLARES_FUNCTION_P (scope
))
678 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
679 else if (TYPE_P (scope
))
680 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
684 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
685 if (protected_accessible_p (decl
, TREE_VALUE (t
), type
, otype
))
688 /* Nested classes have the same access as their enclosing types, as
689 per DR 45 (this is a change from C++98). */
691 if (friend_accessible_p (TYPE_CONTEXT (scope
), decl
, type
, otype
))
694 if (DECL_DECLARES_FUNCTION_P (scope
))
696 /* Perhaps this SCOPE is a member of a class which is a
698 if (DECL_CLASS_SCOPE_P (scope
)
699 && friend_accessible_p (DECL_CONTEXT (scope
), decl
, type
, otype
))
703 /* Maybe scope's template is a friend. */
704 if (tree tinfo
= get_template_info (scope
))
706 tree tmpl
= TI_TEMPLATE (tinfo
);
707 if (DECL_CLASS_TEMPLATE_P (tmpl
))
708 tmpl
= TREE_TYPE (tmpl
);
710 tmpl
= DECL_TEMPLATE_RESULT (tmpl
);
713 /* Increment processing_template_decl to make sure that
714 dependent_type_p works correctly. */
715 ++processing_template_decl
;
716 int ret
= friend_accessible_p (tmpl
, decl
, type
, otype
);
717 --processing_template_decl
;
723 /* If is_friend is true, we should have found a befriending class. */
724 gcc_checking_assert (!is_friend (type
, scope
));
729 struct dfs_accessible_data
735 /* Avoid walking up past a declaration of the member. */
738 dfs_accessible_pre (tree binfo
, void *data
)
740 dfs_accessible_data
*d
= (dfs_accessible_data
*)data
;
741 tree type
= BINFO_TYPE (binfo
);
742 if (member_declared_in_type (d
->decl
, type
))
743 return dfs_skip_bases
;
747 /* Called via dfs_walk_once_accessible from accessible_p */
750 dfs_accessible_post (tree binfo
, void *data
)
752 /* access_in_type already set BINFO_ACCESS for us. */
753 access_kind access
= BINFO_ACCESS (binfo
);
754 tree N
= BINFO_TYPE (binfo
);
755 dfs_accessible_data
*d
= (dfs_accessible_data
*)data
;
757 tree scope
= current_nonlambda_scope ();
759 /* A member m is accessible at the point R when named in class N if */
766 /* m as a member of N is public, or */
771 /* m as a member of N is private, and R occurs in a member or friend of
773 if (scope
&& TREE_CODE (scope
) != NAMESPACE_DECL
774 && is_friend (N
, scope
))
781 /* m as a member of N is protected, and R occurs in a member or friend
782 of class N, or in a member or friend of a class P derived from N,
783 where m as a member of P is public, private, or protected */
784 if (friend_accessible_p (scope
, decl
, N
, d
->object_type
))
794 /* Like accessible_p below, but within a template returns true iff DECL is
795 accessible in TYPE to all possible instantiations of the template. */
798 accessible_in_template_p (tree type
, tree decl
)
800 int save_ptd
= processing_template_decl
;
801 processing_template_decl
= 0;
802 int val
= accessible_p (type
, decl
, false);
803 processing_template_decl
= save_ptd
;
807 /* DECL is a declaration from a base class of TYPE, which was the
808 class used to name DECL. Return nonzero if, in the current
809 context, DECL is accessible. If TYPE is actually a BINFO node,
810 then we can tell in what context the access is occurring by looking
811 at the most derived class along the path indicated by BINFO. If
812 CONSIDER_LOCAL is true, do consider special access the current
813 scope or friendship thereof we might have. */
816 accessible_p (tree type
, tree decl
, bool consider_local_p
)
821 /* If this declaration is in a block or namespace scope, there's no
823 if (!TYPE_P (context_for_name_lookup (decl
)))
826 /* There is no need to perform access checks inside a thunk. */
827 if (current_function_decl
&& DECL_THUNK_P (current_function_decl
))
830 tree otype
= NULL_TREE
;
833 /* When accessing a non-static member, the most derived type in the
834 binfo chain is the type of the object; remember that type for
835 protected_accessible_p. */
836 for (tree b
= type
; b
; b
= BINFO_INHERITANCE_CHAIN (b
))
837 otype
= BINFO_TYPE (b
);
838 type
= BINFO_TYPE (type
);
843 /* [class.access.base]
845 A member m is accessible when named in class N if
847 --m as a member of N is public, or
849 --m as a member of N is private, and the reference occurs in a
850 member or friend of class N, or
852 --m as a member of N is protected, and the reference occurs in a
853 member or friend of class N, or in a member or friend of a
854 class P derived from N, where m as a member of P is public, private or
857 --there exists a base class B of N that is accessible at the point
858 of reference, and m is accessible when named in class B.
860 We walk the base class hierarchy, checking these conditions. */
862 /* We walk using TYPE_BINFO (type) because access_in_type will set
863 BINFO_ACCESS on it and its bases. */
864 binfo
= TYPE_BINFO (type
);
866 /* Compute the accessibility of DECL in the class hierarchy
867 dominated by type. */
868 access
= access_in_type (type
, decl
);
869 if (access
== ak_public
)
872 /* If we aren't considering the point of reference, only the first bullet
874 if (!consider_local_p
)
877 dfs_accessible_data d
= { decl
, otype
};
879 /* Walk the hierarchy again, looking for a base class that allows
881 return dfs_walk_once_accessible (binfo
, /*friends=*/true,
883 dfs_accessible_post
, &d
)
887 struct lookup_field_info
{
888 /* The type in which we're looking. */
890 /* The name of the field for which we're looking. */
892 /* If non-NULL, the current result of the lookup. */
894 /* The path to RVAL. */
896 /* If non-NULL, the lookup was ambiguous, and this is a list of the
899 /* If nonzero, we are looking for types, not data members. */
901 /* If something went wrong, a message indicating what. */
905 /* Nonzero for a class member means that it is shared between all objects
908 [class.member.lookup]:If the resulting set of declarations are not all
909 from sub-objects of the same type, or the set has a non-static member
910 and includes members from distinct sub-objects, there is an ambiguity
911 and the program is ill-formed.
913 This function checks that T contains no non-static members. */
916 shared_member_p (tree t
)
918 if (VAR_P (t
) || TREE_CODE (t
) == TYPE_DECL \
919 || TREE_CODE (t
) == CONST_DECL
)
921 if (is_overloaded_fn (t
))
923 for (ovl_iterator
iter (get_fns (t
)); iter
; ++iter
)
925 tree decl
= strip_using_decl (*iter
);
926 /* We don't expect or support dependent decls. */
927 gcc_assert (TREE_CODE (decl
) != USING_DECL
);
928 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
))
936 /* Routine to see if the sub-object denoted by the binfo PARENT can be
937 found as a base class and sub-object of the object denoted by
941 is_subobject_of_p (tree parent
, tree binfo
)
945 for (probe
= parent
; probe
; probe
= BINFO_INHERITANCE_CHAIN (probe
))
949 if (BINFO_VIRTUAL_P (probe
))
950 return (binfo_for_vbase (BINFO_TYPE (probe
), BINFO_TYPE (binfo
))
956 /* DATA is really a struct lookup_field_info. Look for a field with
957 the name indicated there in BINFO. If this function returns a
958 non-NULL value it is the result of the lookup. Called from
959 lookup_field via breadth_first_search. */
962 lookup_field_r (tree binfo
, void *data
)
964 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
965 tree type
= BINFO_TYPE (binfo
);
966 tree nval
= NULL_TREE
;
968 /* If this is a dependent base, don't look in it. */
969 if (BINFO_DEPENDENT_BASE_P (binfo
))
972 /* If this base class is hidden by the best-known value so far, we
973 don't need to look. */
974 if (lfi
->rval_binfo
&& BINFO_INHERITANCE_CHAIN (binfo
) == lfi
->rval_binfo
975 && !BINFO_VIRTUAL_P (binfo
))
976 return dfs_skip_bases
;
978 nval
= get_class_binding (type
, lfi
->name
, lfi
->want_type
);
980 /* If we're looking up a type (as with an elaborated type specifier)
981 we ignore all non-types we find. */
982 if (lfi
->want_type
&& nval
&& !DECL_DECLARES_TYPE_P (nval
))
985 if (CLASSTYPE_NESTED_UTDS (type
))
986 if (binding_entry e
= binding_table_find (CLASSTYPE_NESTED_UTDS (type
),
988 nval
= TYPE_MAIN_DECL (e
->type
);
991 /* If there is no declaration with the indicated name in this type,
992 then there's nothing to do. */
996 /* If the lookup already found a match, and the new value doesn't
997 hide the old one, we might have an ambiguity. */
999 && !is_subobject_of_p (lfi
->rval_binfo
, binfo
))
1002 if (nval
== lfi
->rval
&& shared_member_p (nval
))
1003 /* The two things are really the same. */
1005 else if (is_subobject_of_p (binfo
, lfi
->rval_binfo
))
1006 /* The previous value hides the new one. */
1010 /* We have a real ambiguity. We keep a chain of all the
1012 if (!lfi
->ambiguous
&& lfi
->rval
)
1014 /* This is the first time we noticed an ambiguity. Add
1015 what we previously thought was a reasonable candidate
1017 lfi
->ambiguous
= tree_cons (NULL_TREE
, lfi
->rval
, NULL_TREE
);
1018 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1021 /* Add the new value. */
1022 lfi
->ambiguous
= tree_cons (NULL_TREE
, nval
, lfi
->ambiguous
);
1023 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1024 lfi
->errstr
= G_("request for member %qD is ambiguous");
1030 lfi
->rval_binfo
= binfo
;
1034 /* Don't look for constructors or destructors in base classes. */
1035 if (IDENTIFIER_CDTOR_P (lfi
->name
))
1036 return dfs_skip_bases
;
1040 /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1041 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1042 FUNCTIONS, and OPTYPE respectively. */
1045 build_baselink (tree binfo
, tree access_binfo
, tree functions
, tree optype
)
1049 gcc_assert (OVL_P (functions
) || TREE_CODE (functions
) == TEMPLATE_ID_EXPR
);
1050 gcc_assert (!optype
|| TYPE_P (optype
));
1051 gcc_assert (TREE_TYPE (functions
));
1053 baselink
= make_node (BASELINK
);
1054 TREE_TYPE (baselink
) = TREE_TYPE (functions
);
1055 BASELINK_BINFO (baselink
) = binfo
;
1056 BASELINK_ACCESS_BINFO (baselink
) = access_binfo
;
1057 BASELINK_FUNCTIONS (baselink
) = functions
;
1058 BASELINK_OPTYPE (baselink
) = optype
;
1063 /* Look for a member named NAME in an inheritance lattice dominated by
1064 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1065 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1066 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1067 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1068 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1069 TREE_VALUEs are the list of ambiguous candidates.
1071 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1073 If nothing can be found return NULL_TREE and do not issue an error.
1075 If non-NULL, failure information is written back to AFI. */
1078 lookup_member (tree xbasetype
, tree name
, int protect
, bool want_type
,
1079 tsubst_flags_t complain
, access_failure_info
*afi
)
1081 tree rval
, rval_binfo
= NULL_TREE
;
1082 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1083 struct lookup_field_info lfi
;
1085 /* rval_binfo is the binfo associated with the found member, note,
1086 this can be set with useful information, even when rval is not
1087 set, because it must deal with ALL members, not just non-function
1088 members. It is used for ambiguity checking and the hidden
1089 checks. Whereas rval is only set if a proper (not hidden)
1090 non-function member is found. */
1092 const char *errstr
= 0;
1094 if (name
== error_mark_node
1095 || xbasetype
== NULL_TREE
1096 || xbasetype
== error_mark_node
)
1099 gcc_assert (identifier_p (name
));
1101 if (TREE_CODE (xbasetype
) == TREE_BINFO
)
1103 type
= BINFO_TYPE (xbasetype
);
1104 basetype_path
= xbasetype
;
1108 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype
)))
1111 xbasetype
= NULL_TREE
;
1114 type
= complete_type (type
);
1116 /* Make sure we're looking for a member of the current instantiation in the
1117 right partial specialization. */
1118 if (dependent_type_p (type
))
1119 if (tree t
= currently_open_class (type
))
1123 basetype_path
= TYPE_BINFO (type
);
1128 memset (&lfi
, 0, sizeof (lfi
));
1131 lfi
.want_type
= want_type
;
1132 dfs_walk_all (basetype_path
, &lookup_field_r
, NULL
, &lfi
);
1134 rval_binfo
= lfi
.rval_binfo
;
1136 type
= BINFO_TYPE (rval_binfo
);
1137 errstr
= lfi
.errstr
;
1139 /* If we are not interested in ambiguities, don't report them;
1140 just return NULL_TREE. */
1141 if (!protect
&& lfi
.ambiguous
)
1147 return lfi
.ambiguous
;
1154 In the case of overloaded function names, access control is
1155 applied to the function selected by overloaded resolution.
1157 We cannot check here, even if RVAL is only a single non-static
1158 member function, since we do not know what the "this" pointer
1161 class A { protected: void f(); };
1162 class B : public A {
1169 only the first call to "f" is valid. However, if the function is
1170 static, we can check. */
1172 && !really_overloaded_fn (rval
))
1174 tree decl
= is_overloaded_fn (rval
) ? get_first_fn (rval
) : rval
;
1175 decl
= strip_using_decl (decl
);
1176 /* A dependent USING_DECL will be checked after tsubsting. */
1177 if (TREE_CODE (decl
) != USING_DECL
1178 && !DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
1179 && !perform_or_defer_access_check (basetype_path
, decl
, decl
,
1181 rval
= error_mark_node
;
1184 if (errstr
&& protect
)
1186 if (complain
& tf_error
)
1188 error (errstr
, name
, type
);
1190 print_candidates (lfi
.ambiguous
);
1192 rval
= error_mark_node
;
1195 if (rval
&& is_overloaded_fn (rval
))
1196 rval
= build_baselink (rval_binfo
, basetype_path
, rval
,
1197 (IDENTIFIER_CONV_OP_P (name
)
1198 ? TREE_TYPE (name
): NULL_TREE
));
1202 /* Helper class for lookup_member_fuzzy. */
1204 class lookup_field_fuzzy_info
1207 lookup_field_fuzzy_info (bool want_type_p
) :
1208 m_want_type_p (want_type_p
), m_candidates () {}
1210 void fuzzy_lookup_field (tree type
);
1212 /* If true, we are looking for types, not data members. */
1214 /* The result: a vec of identifiers. */
1215 auto_vec
<tree
> m_candidates
;
1218 /* Locate all fields within TYPE, append them to m_candidates. */
1221 lookup_field_fuzzy_info::fuzzy_lookup_field (tree type
)
1223 if (!CLASS_TYPE_P (type
))
1226 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1228 if (m_want_type_p
&& !DECL_DECLARES_TYPE_P (field
))
1231 if (!DECL_NAME (field
))
1234 if (is_lambda_ignored_entity (field
))
1237 m_candidates
.safe_push (DECL_NAME (field
));
1242 /* Helper function for lookup_member_fuzzy, called via dfs_walk_all
1243 DATA is really a lookup_field_fuzzy_info. Look for a field with
1244 the name indicated there in BINFO. Gathers pertinent identifiers into
1248 lookup_field_fuzzy_r (tree binfo
, void *data
)
1250 lookup_field_fuzzy_info
*lffi
= (lookup_field_fuzzy_info
*) data
;
1251 tree type
= BINFO_TYPE (binfo
);
1253 lffi
->fuzzy_lookup_field (type
);
1258 /* Like lookup_member, but try to find the closest match for NAME,
1259 rather than an exact match, and return an identifier (or NULL_TREE).
1263 lookup_member_fuzzy (tree xbasetype
, tree name
, bool want_type_p
)
1265 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1266 class lookup_field_fuzzy_info
lffi (want_type_p
);
1268 /* rval_binfo is the binfo associated with the found member, note,
1269 this can be set with useful information, even when rval is not
1270 set, because it must deal with ALL members, not just non-function
1271 members. It is used for ambiguity checking and the hidden
1272 checks. Whereas rval is only set if a proper (not hidden)
1273 non-function member is found. */
1275 if (name
== error_mark_node
1276 || xbasetype
== NULL_TREE
1277 || xbasetype
== error_mark_node
)
1280 gcc_assert (identifier_p (name
));
1282 if (TREE_CODE (xbasetype
) == TREE_BINFO
)
1284 type
= BINFO_TYPE (xbasetype
);
1285 basetype_path
= xbasetype
;
1289 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype
)))
1292 xbasetype
= NULL_TREE
;
1295 type
= complete_type (type
);
1297 /* Make sure we're looking for a member of the current instantiation in the
1298 right partial specialization. */
1299 if (flag_concepts
&& dependent_type_p (type
))
1300 type
= currently_open_class (type
);
1303 basetype_path
= TYPE_BINFO (type
);
1308 /* Populate lffi.m_candidates. */
1309 dfs_walk_all (basetype_path
, &lookup_field_fuzzy_r
, NULL
, &lffi
);
1311 return find_closest_identifier (name
, &lffi
.m_candidates
);
1314 /* Like lookup_member, except that if we find a function member we
1315 return NULL_TREE. */
1318 lookup_field (tree xbasetype
, tree name
, int protect
, bool want_type
)
1320 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
,
1321 tf_warning_or_error
);
1323 /* Ignore functions, but propagate the ambiguity list. */
1324 if (!error_operand_p (rval
)
1325 && (rval
&& BASELINK_P (rval
)))
1331 /* Like lookup_member, except that if we find a non-function member we
1332 return NULL_TREE. */
1335 lookup_fnfields (tree xbasetype
, tree name
, int protect
,
1336 tsubst_flags_t complain
)
1338 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/false,
1341 /* Ignore non-functions, but propagate the ambiguity list. */
1342 if (!error_operand_p (rval
)
1343 && (rval
&& !BASELINK_P (rval
)))
1349 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1350 the class or namespace used to qualify the name. CONTEXT_CLASS is
1351 the class corresponding to the object in which DECL will be used.
1352 Return a possibly modified version of DECL that takes into account
1355 In particular, consider an expression like `B::m' in the context of
1356 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1357 then the most derived class indicated by the BASELINK_BINFO will be
1358 `B', not `D'. This function makes that adjustment. */
1361 adjust_result_of_qualified_name_lookup (tree decl
,
1362 tree qualifying_scope
,
1365 if (context_class
&& context_class
!= error_mark_node
1366 && CLASS_TYPE_P (context_class
)
1367 && CLASS_TYPE_P (qualifying_scope
)
1368 && DERIVED_FROM_P (qualifying_scope
, context_class
)
1369 && BASELINK_P (decl
))
1373 /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
1374 Because we do not yet know which function will be chosen by
1375 overload resolution, we cannot yet check either accessibility
1376 or ambiguity -- in either case, the choice of a static member
1377 function might make the usage valid. */
1378 base
= lookup_base (context_class
, qualifying_scope
,
1379 ba_unique
, NULL
, tf_none
);
1380 if (base
&& base
!= error_mark_node
)
1382 BASELINK_ACCESS_BINFO (decl
) = base
;
1384 = lookup_base (base
, BINFO_TYPE (BASELINK_BINFO (decl
)),
1385 ba_unique
, NULL
, tf_none
);
1386 if (decl_binfo
&& decl_binfo
!= error_mark_node
)
1387 BASELINK_BINFO (decl
) = decl_binfo
;
1391 if (BASELINK_P (decl
))
1392 BASELINK_QUALIFIED_P (decl
) = true;
1398 /* Walk the class hierarchy within BINFO, in a depth-first traversal.
1399 PRE_FN is called in preorder, while POST_FN is called in postorder.
1400 If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
1401 walked. If PRE_FN or POST_FN returns a different non-NULL value,
1402 that value is immediately returned and the walk is terminated. One
1403 of PRE_FN and POST_FN can be NULL. At each node, PRE_FN and
1404 POST_FN are passed the binfo to examine and the caller's DATA
1405 value. All paths are walked, thus virtual and morally virtual
1406 binfos can be multiply walked. */
1409 dfs_walk_all (tree binfo
, tree (*pre_fn
) (tree
, void *),
1410 tree (*post_fn
) (tree
, void *), void *data
)
1416 /* Call the pre-order walking function. */
1419 rval
= pre_fn (binfo
, data
);
1422 if (rval
== dfs_skip_bases
)
1428 /* Find the next child binfo to walk. */
1429 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1431 rval
= dfs_walk_all (base_binfo
, pre_fn
, post_fn
, data
);
1437 /* Call the post-order walking function. */
1440 rval
= post_fn (binfo
, data
);
1441 gcc_assert (rval
!= dfs_skip_bases
);
1448 /* Worker for dfs_walk_once. This behaves as dfs_walk_all, except
1449 that binfos are walked at most once. */
1452 dfs_walk_once_r (tree binfo
, tree (*pre_fn
) (tree
, void *),
1453 tree (*post_fn
) (tree
, void *), hash_set
<tree
> *pset
,
1460 /* Call the pre-order walking function. */
1463 rval
= pre_fn (binfo
, data
);
1466 if (rval
== dfs_skip_bases
)
1473 /* Find the next child binfo to walk. */
1474 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1476 if (BINFO_VIRTUAL_P (base_binfo
))
1477 if (pset
->add (base_binfo
))
1480 rval
= dfs_walk_once_r (base_binfo
, pre_fn
, post_fn
, pset
, data
);
1486 /* Call the post-order walking function. */
1489 rval
= post_fn (binfo
, data
);
1490 gcc_assert (rval
!= dfs_skip_bases
);
1497 /* Like dfs_walk_all, except that binfos are not multiply walked. For
1498 non-diamond shaped hierarchies this is the same as dfs_walk_all.
1499 For diamond shaped hierarchies we must mark the virtual bases, to
1500 avoid multiple walks. */
1503 dfs_walk_once (tree binfo
, tree (*pre_fn
) (tree
, void *),
1504 tree (*post_fn
) (tree
, void *), void *data
)
1506 static int active
= 0; /* We must not be called recursively. */
1509 gcc_assert (pre_fn
|| post_fn
);
1510 gcc_assert (!active
);
1513 if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo
)))
1514 /* We are not diamond shaped, and therefore cannot encounter the
1515 same binfo twice. */
1516 rval
= dfs_walk_all (binfo
, pre_fn
, post_fn
, data
);
1519 hash_set
<tree
> pset
;
1520 rval
= dfs_walk_once_r (binfo
, pre_fn
, post_fn
, &pset
, data
);
1528 /* Worker function for dfs_walk_once_accessible. Behaves like
1529 dfs_walk_once_r, except (a) FRIENDS_P is true if special
1530 access given by the current context should be considered, (b) ONCE
1531 indicates whether bases should be marked during traversal. */
1534 dfs_walk_once_accessible_r (tree binfo
, bool friends_p
, hash_set
<tree
> *pset
,
1535 tree (*pre_fn
) (tree
, void *),
1536 tree (*post_fn
) (tree
, void *), void *data
)
1538 tree rval
= NULL_TREE
;
1542 /* Call the pre-order walking function. */
1545 rval
= pre_fn (binfo
, data
);
1548 if (rval
== dfs_skip_bases
)
1555 /* Find the next child binfo to walk. */
1556 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1558 bool mark
= pset
&& BINFO_VIRTUAL_P (base_binfo
);
1560 if (mark
&& pset
->contains (base_binfo
))
1563 /* If the base is inherited via private or protected
1564 inheritance, then we can't see it, unless we are a friend of
1565 the current binfo. */
1566 if (BINFO_BASE_ACCESS (binfo
, ix
) != access_public_node
)
1571 scope
= current_scope ();
1573 || TREE_CODE (scope
) == NAMESPACE_DECL
1574 || !is_friend (BINFO_TYPE (binfo
), scope
))
1579 pset
->add (base_binfo
);
1581 rval
= dfs_walk_once_accessible_r (base_binfo
, friends_p
, pset
,
1582 pre_fn
, post_fn
, data
);
1588 /* Call the post-order walking function. */
1591 rval
= post_fn (binfo
, data
);
1592 gcc_assert (rval
!= dfs_skip_bases
);
1599 /* Like dfs_walk_once except that only accessible bases are walked.
1600 FRIENDS_P indicates whether friendship of the local context
1601 should be considered when determining accessibility. */
1604 dfs_walk_once_accessible (tree binfo
, bool friends_p
,
1605 tree (*pre_fn
) (tree
, void *),
1606 tree (*post_fn
) (tree
, void *), void *data
)
1608 hash_set
<tree
> *pset
= NULL
;
1609 if (CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo
)))
1610 pset
= new hash_set
<tree
>;
1611 tree rval
= dfs_walk_once_accessible_r (binfo
, friends_p
, pset
,
1612 pre_fn
, post_fn
, data
);
1619 /* Return true iff the code of T is CODE, and it has compatible
1623 matches_code_and_type_p (tree t
, enum tree_code code
, tree type
)
1625 if (TREE_CODE (t
) != code
)
1627 if (!cxx_types_compatible_p (TREE_TYPE (t
), type
))
1632 /* Subroutine of direct_accessor_p and reference_accessor_p.
1633 Determine if COMPONENT_REF is a simple field lookup of this->FIELD_DECL.
1634 We expect a tree of the form:
1639 <field_decl (FIELD_DECL)>>>. */
1642 field_access_p (tree component_ref
, tree field_decl
, tree field_type
)
1644 if (!matches_code_and_type_p (component_ref
, COMPONENT_REF
, field_type
))
1647 tree indirect_ref
= TREE_OPERAND (component_ref
, 0);
1648 if (!INDIRECT_REF_P (indirect_ref
))
1651 tree ptr
= STRIP_NOPS (TREE_OPERAND (indirect_ref
, 0));
1652 if (!is_this_parameter (ptr
))
1655 /* Must access the correct field. */
1656 if (TREE_OPERAND (component_ref
, 1) != field_decl
)
1661 /* Subroutine of field_accessor_p.
1663 Assuming that INIT_EXPR has already had its code and type checked,
1664 determine if it is a simple accessor for FIELD_DECL
1665 (of type FIELD_TYPE).
1667 Specifically, a simple accessor within struct S of the form:
1668 T get_field () { return m_field; }
1669 should have a constexpr_fn_retval (saved_tree) of the form:
1677 <field_decl (FIELD_DECL)>>>>>. */
1680 direct_accessor_p (tree init_expr
, tree field_decl
, tree field_type
)
1682 tree result_decl
= TREE_OPERAND (init_expr
, 0);
1683 if (!matches_code_and_type_p (result_decl
, RESULT_DECL
, field_type
))
1686 tree component_ref
= STRIP_NOPS (TREE_OPERAND (init_expr
, 1));
1687 if (!field_access_p (component_ref
, field_decl
, field_type
))
1693 /* Subroutine of field_accessor_p.
1695 Assuming that INIT_EXPR has already had its code and type checked,
1696 determine if it is a "reference" accessor for FIELD_DECL
1697 (of type FIELD_REFERENCE_TYPE).
1699 Specifically, a simple accessor within struct S of the form:
1700 T& get_field () { return m_field; }
1701 should have a constexpr_fn_retval (saved_tree) of the form:
1710 <field (FIELD_DECL)>>>>>>. */
1712 reference_accessor_p (tree init_expr
, tree field_decl
, tree field_type
,
1713 tree field_reference_type
)
1715 tree result_decl
= TREE_OPERAND (init_expr
, 0);
1716 if (!matches_code_and_type_p (result_decl
, RESULT_DECL
, field_reference_type
))
1719 tree field_pointer_type
= build_pointer_type (field_type
);
1720 tree addr_expr
= STRIP_NOPS (TREE_OPERAND (init_expr
, 1));
1721 if (!matches_code_and_type_p (addr_expr
, ADDR_EXPR
, field_pointer_type
))
1724 tree component_ref
= STRIP_NOPS (TREE_OPERAND (addr_expr
, 0));
1726 if (!field_access_p (component_ref
, field_decl
, field_type
))
1732 /* Return true if FN is an accessor method for FIELD_DECL.
1733 i.e. a method of the form { return FIELD; }, with no
1736 If CONST_P, then additionally require that FN be a const
1740 field_accessor_p (tree fn
, tree field_decl
, bool const_p
)
1742 if (TREE_CODE (fn
) != FUNCTION_DECL
)
1745 /* We don't yet support looking up static data, just fields. */
1746 if (TREE_CODE (field_decl
) != FIELD_DECL
)
1749 tree fntype
= TREE_TYPE (fn
);
1750 if (TREE_CODE (fntype
) != METHOD_TYPE
)
1753 /* If the field is accessed via a const "this" argument, verify
1754 that the "this" parameter is const. */
1757 tree this_class
= class_of_this_parm (fntype
);
1758 if (!TYPE_READONLY (this_class
))
1762 tree saved_tree
= DECL_SAVED_TREE (fn
);
1764 if (saved_tree
== NULL_TREE
)
1767 /* Attempt to extract a single return value from the function,
1769 tree retval
= constexpr_fn_retval (saved_tree
);
1770 if (retval
== NULL_TREE
|| retval
== error_mark_node
)
1772 /* Require an INIT_EXPR. */
1773 if (TREE_CODE (retval
) != INIT_EXPR
)
1775 tree init_expr
= retval
;
1777 /* Determine if this is a simple accessor within struct S of the form:
1778 T get_field () { return m_field; }. */
1779 tree field_type
= TREE_TYPE (field_decl
);
1780 if (cxx_types_compatible_p (TREE_TYPE (init_expr
), field_type
))
1781 return direct_accessor_p (init_expr
, field_decl
, field_type
);
1783 /* Failing that, determine if it is an accessor of the form:
1784 T& get_field () { return m_field; }. */
1785 tree field_reference_type
= cp_build_reference_type (field_type
, false);
1786 if (cxx_types_compatible_p (TREE_TYPE (init_expr
), field_reference_type
))
1787 return reference_accessor_p (init_expr
, field_decl
, field_type
,
1788 field_reference_type
);
1793 /* Callback data for dfs_locate_field_accessor_pre. */
1795 class locate_field_data
1798 locate_field_data (tree field_decl_
, bool const_p_
)
1799 : field_decl (field_decl_
), const_p (const_p_
) {}
1805 /* Return a FUNCTION_DECL that is an "accessor" method for DATA, a FIELD_DECL,
1806 callable via binfo, if one exists, otherwise return NULL_TREE.
1808 Callback for dfs_walk_once_accessible for use within
1809 locate_field_accessor. */
1812 dfs_locate_field_accessor_pre (tree binfo
, void *data
)
1814 locate_field_data
*lfd
= (locate_field_data
*)data
;
1815 tree type
= BINFO_TYPE (binfo
);
1817 vec
<tree
, va_gc
> *member_vec
;
1821 if (!CLASS_TYPE_P (type
))
1824 member_vec
= CLASSTYPE_MEMBER_VEC (type
);
1828 for (i
= 0; vec_safe_iterate (member_vec
, i
, &fn
); ++i
)
1830 if (field_accessor_p (fn
, lfd
->field_decl
, lfd
->const_p
))
1836 /* Return a FUNCTION_DECL that is an "accessor" method for FIELD_DECL,
1837 callable via BASETYPE_PATH, if one exists, otherwise return NULL_TREE. */
1840 locate_field_accessor (tree basetype_path
, tree field_decl
, bool const_p
)
1842 if (TREE_CODE (basetype_path
) != TREE_BINFO
)
1845 /* Walk the hierarchy, looking for a method of some base class that allows
1846 access to the field. */
1847 locate_field_data
lfd (field_decl
, const_p
);
1848 return dfs_walk_once_accessible (basetype_path
, /*friends=*/true,
1849 dfs_locate_field_accessor_pre
,
1853 /* Check throw specifier of OVERRIDER is at least as strict as
1854 the one of BASEFN. */
1857 maybe_check_overriding_exception_spec (tree overrider
, tree basefn
)
1859 maybe_instantiate_noexcept (basefn
);
1860 maybe_instantiate_noexcept (overrider
);
1861 tree base_throw
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn
));
1862 tree over_throw
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider
));
1864 if (DECL_INVALID_OVERRIDER_P (overrider
))
1867 /* Can't check this yet. Pretend this is fine and let
1868 noexcept_override_late_checks check this later. */
1869 if (UNPARSED_NOEXCEPT_SPEC_P (base_throw
)
1870 || UNPARSED_NOEXCEPT_SPEC_P (over_throw
))
1873 if (!comp_except_specs (base_throw
, over_throw
, ce_derived
))
1875 auto_diagnostic_group d
;
1876 error ("looser exception specification on overriding virtual function "
1877 "%q+#F", overrider
);
1878 inform (DECL_SOURCE_LOCATION (basefn
),
1879 "overridden function is %q#F", basefn
);
1880 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1886 /* Check that virtual overrider OVERRIDER is acceptable for base function
1887 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1890 check_final_overrider (tree overrider
, tree basefn
)
1892 tree over_type
= TREE_TYPE (overrider
);
1893 tree base_type
= TREE_TYPE (basefn
);
1894 tree over_return
= fndecl_declared_return_type (overrider
);
1895 tree base_return
= fndecl_declared_return_type (basefn
);
1899 if (DECL_INVALID_OVERRIDER_P (overrider
))
1902 if (same_type_p (base_return
, over_return
))
1904 else if ((CLASS_TYPE_P (over_return
) && CLASS_TYPE_P (base_return
))
1905 || (TREE_CODE (base_return
) == TREE_CODE (over_return
)
1906 && INDIRECT_TYPE_P (base_return
)))
1908 /* Potentially covariant. */
1909 unsigned base_quals
, over_quals
;
1911 fail
= !INDIRECT_TYPE_P (base_return
);
1914 fail
= cp_type_quals (base_return
) != cp_type_quals (over_return
);
1916 base_return
= TREE_TYPE (base_return
);
1917 over_return
= TREE_TYPE (over_return
);
1919 base_quals
= cp_type_quals (base_return
);
1920 over_quals
= cp_type_quals (over_return
);
1922 if ((base_quals
& over_quals
) != over_quals
)
1925 if (CLASS_TYPE_P (base_return
) && CLASS_TYPE_P (over_return
))
1927 /* Strictly speaking, the standard requires the return type to be
1928 complete even if it only differs in cv-quals, but that seems
1929 like a bug in the wording. */
1930 if (!same_type_ignoring_top_level_qualifiers_p (base_return
,
1933 tree binfo
= lookup_base (over_return
, base_return
,
1934 ba_check
, NULL
, tf_none
);
1936 if (!binfo
|| binfo
== error_mark_node
)
1940 else if (can_convert_standard (TREE_TYPE (base_type
),
1941 TREE_TYPE (over_type
),
1942 tf_warning_or_error
))
1943 /* GNU extension, allow trivial pointer conversions such as
1944 converting to void *, or qualification conversion. */
1946 auto_diagnostic_group d
;
1947 if (pedwarn (DECL_SOURCE_LOCATION (overrider
), 0,
1948 "invalid covariant return type for %q#D", overrider
))
1949 inform (DECL_SOURCE_LOCATION (basefn
),
1950 "overridden function is %q#D", basefn
);
1961 auto_diagnostic_group d
;
1963 error ("invalid covariant return type for %q+#D", overrider
);
1965 error ("conflicting return type specified for %q+#D", overrider
);
1966 inform (DECL_SOURCE_LOCATION (basefn
),
1967 "overridden function is %q#D", basefn
);
1968 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1972 if (!maybe_check_overriding_exception_spec (overrider
, basefn
))
1975 /* Check for conflicting type attributes. But leave transaction_safe for
1976 set_one_vmethod_tm_attributes. */
1977 if (!comp_type_attributes (over_type
, base_type
)
1978 && !tx_safe_fn_type_p (base_type
)
1979 && !tx_safe_fn_type_p (over_type
))
1981 auto_diagnostic_group d
;
1982 error ("conflicting type attributes specified for %q+#D", overrider
);
1983 inform (DECL_SOURCE_LOCATION (basefn
),
1984 "overridden function is %q#D", basefn
);
1985 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1989 /* A consteval virtual function shall not override a virtual function that is
1990 not consteval. A consteval virtual function shall not be overridden by a
1991 virtual function that is not consteval. */
1992 if (DECL_IMMEDIATE_FUNCTION_P (overrider
)
1993 != DECL_IMMEDIATE_FUNCTION_P (basefn
))
1995 auto_diagnostic_group d
;
1996 if (DECL_IMMEDIATE_FUNCTION_P (overrider
))
1997 error ("%<consteval%> function %q+D overriding non-%<consteval%> "
1998 "function", overrider
);
2000 error ("non-%<consteval%> function %q+D overriding %<consteval%> "
2001 "function", overrider
);
2002 inform (DECL_SOURCE_LOCATION (basefn
),
2003 "overridden function is %qD", basefn
);
2004 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
2008 /* A function declared transaction_safe_dynamic that overrides a function
2009 declared transaction_safe (but not transaction_safe_dynamic) is
2011 if (tx_safe_fn_type_p (base_type
)
2012 && lookup_attribute ("transaction_safe_dynamic",
2013 DECL_ATTRIBUTES (overrider
))
2014 && !lookup_attribute ("transaction_safe_dynamic",
2015 DECL_ATTRIBUTES (basefn
)))
2017 auto_diagnostic_group d
;
2018 error_at (DECL_SOURCE_LOCATION (overrider
),
2019 "%qD declared %<transaction_safe_dynamic%>", overrider
);
2020 inform (DECL_SOURCE_LOCATION (basefn
),
2021 "overriding %qD declared %<transaction_safe%>", basefn
);
2024 if (DECL_DELETED_FN (basefn
) != DECL_DELETED_FN (overrider
))
2026 if (DECL_DELETED_FN (overrider
))
2028 auto_diagnostic_group d
;
2029 error ("deleted function %q+D overriding non-deleted function",
2031 inform (DECL_SOURCE_LOCATION (basefn
),
2032 "overridden function is %qD", basefn
);
2033 maybe_explain_implicit_delete (overrider
);
2037 auto_diagnostic_group d
;
2038 error ("non-deleted function %q+D overriding deleted function",
2040 inform (DECL_SOURCE_LOCATION (basefn
),
2041 "overridden function is %qD", basefn
);
2045 if (DECL_FINAL_P (basefn
))
2047 auto_diagnostic_group d
;
2048 error ("virtual function %q+D overriding final function", overrider
);
2049 inform (DECL_SOURCE_LOCATION (basefn
),
2050 "overridden function is %qD", basefn
);
2056 /* Given a class TYPE, and a function decl FNDECL, look for
2057 virtual functions in TYPE's hierarchy which FNDECL overrides.
2058 We do not look in TYPE itself, only its bases.
2060 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
2061 find that it overrides anything.
2063 We check that every function which is overridden, is correctly
2067 look_for_overrides (tree type
, tree fndecl
)
2069 tree binfo
= TYPE_BINFO (type
);
2074 /* A constructor for a class T does not override a function T
2076 if (DECL_CONSTRUCTOR_P (fndecl
))
2079 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
2081 tree basetype
= BINFO_TYPE (base_binfo
);
2083 if (TYPE_POLYMORPHIC_P (basetype
))
2084 found
+= look_for_overrides_r (basetype
, fndecl
);
2089 /* Look in TYPE for virtual functions with the same signature as
2093 look_for_overrides_here (tree type
, tree fndecl
)
2095 tree ovl
= get_class_binding (type
, DECL_NAME (fndecl
));
2097 for (ovl_iterator
iter (ovl
); iter
; ++iter
)
2101 if (!DECL_VIRTUAL_P (fn
))
2102 /* Not a virtual. */;
2103 else if (DECL_CONTEXT (fn
) != type
)
2104 /* Introduced with a using declaration. */;
2105 else if (DECL_STATIC_FUNCTION_P (fndecl
))
2107 tree btypes
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
2108 tree dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2109 if (compparms (TREE_CHAIN (btypes
), dtypes
))
2112 else if (same_signature_p (fndecl
, fn
))
2119 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
2120 TYPE itself and its bases. */
2123 look_for_overrides_r (tree type
, tree fndecl
)
2125 tree fn
= look_for_overrides_here (type
, fndecl
);
2128 if (DECL_STATIC_FUNCTION_P (fndecl
))
2130 /* A static member function cannot match an inherited
2131 virtual member function. */
2132 auto_diagnostic_group d
;
2133 error ("%q+#D cannot be declared", fndecl
);
2134 error (" since %q+#D declared in base class", fn
);
2138 /* It's definitely virtual, even if not explicitly set. */
2139 DECL_VIRTUAL_P (fndecl
) = 1;
2140 check_final_overrider (fndecl
, fn
);
2145 /* We failed to find one declared in this class. Look in its bases. */
2146 return look_for_overrides (type
, fndecl
);
2149 /* Called via dfs_walk from dfs_get_pure_virtuals. */
2152 dfs_get_pure_virtuals (tree binfo
, void *data
)
2154 tree type
= (tree
) data
;
2156 /* We're not interested in primary base classes; the derived class
2157 of which they are a primary base will contain the information we
2159 if (!BINFO_PRIMARY_P (binfo
))
2163 for (virtuals
= BINFO_VIRTUALS (binfo
);
2165 virtuals
= TREE_CHAIN (virtuals
))
2166 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals
)))
2167 vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type
), BV_FN (virtuals
));
2173 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
2176 get_pure_virtuals (tree type
)
2178 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
2179 is going to be overridden. */
2180 CLASSTYPE_PURE_VIRTUALS (type
) = NULL
;
2181 /* Now, run through all the bases which are not primary bases, and
2182 collect the pure virtual functions. We look at the vtable in
2183 each class to determine what pure virtual functions are present.
2184 (A primary base is not interesting because the derived class of
2185 which it is a primary base will contain vtable entries for the
2186 pure virtuals in the base class. */
2187 dfs_walk_once (TYPE_BINFO (type
), NULL
, dfs_get_pure_virtuals
, type
);
2190 /* Debug info for C++ classes can get very large; try to avoid
2191 emitting it everywhere.
2193 Note that this optimization wins even when the target supports
2194 BINCL (if only slightly), and reduces the amount of work for the
2198 maybe_suppress_debug_info (tree t
)
2200 if (write_symbols
== NO_DEBUG
)
2203 /* We might have set this earlier in cp_finish_decl. */
2204 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 0;
2206 /* Always emit the information for each class every time. */
2207 if (flag_emit_class_debug_always
)
2210 /* If we already know how we're handling this class, handle debug info
2212 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2214 if (CLASSTYPE_INTERFACE_ONLY (t
))
2215 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
2216 /* else don't set it. */
2218 /* If the class has a vtable, write out the debug info along with
2220 else if (TYPE_CONTAINS_VPTR_P (t
))
2221 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
2223 /* Otherwise, just emit the debug info normally. */
2226 /* Note that we want debugging information for a base class of a class
2227 whose vtable is being emitted. Normally, this would happen because
2228 calling the constructor for a derived class implies calling the
2229 constructors for all bases, which involve initializing the
2230 appropriate vptr with the vtable for the base class; but in the
2231 presence of optimization, this initialization may be optimized
2232 away, so we tell finish_vtable_vardecl that we want the debugging
2233 information anyway. */
2236 dfs_debug_mark (tree binfo
, void * /*data*/)
2238 tree t
= BINFO_TYPE (binfo
);
2240 if (CLASSTYPE_DEBUG_REQUESTED (t
))
2241 return dfs_skip_bases
;
2243 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2248 /* Write out the debugging information for TYPE, whose vtable is being
2249 emitted. Also walk through our bases and note that we want to
2250 write out information for them. This avoids the problem of not
2251 writing any debug info for intermediate basetypes whose
2252 constructors, and thus the references to their vtables, and thus
2253 the vtables themselves, were optimized away. */
2256 note_debug_info_needed (tree type
)
2258 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)))
2260 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)) = 0;
2261 rest_of_type_compilation (type
, namespace_bindings_p ());
2264 dfs_walk_all (TYPE_BINFO (type
), dfs_debug_mark
, NULL
, 0);
2267 /* Helper for lookup_conversions_r. TO_TYPE is the type converted to
2268 by a conversion op in base BINFO. VIRTUAL_DEPTH is nonzero if
2269 BINFO is morally virtual, and VIRTUALNESS is nonzero if virtual
2270 bases have been encountered already in the tree walk. PARENT_CONVS
2271 is the list of lists of conversion functions that could hide CONV
2272 and OTHER_CONVS is the list of lists of conversion functions that
2273 could hide or be hidden by CONV, should virtualness be involved in
2274 the hierarchy. Merely checking the conversion op's name is not
2275 enough because two conversion operators to the same type can have
2276 different names. Return nonzero if we are visible. */
2279 check_hidden_convs (tree binfo
, int virtual_depth
, int virtualness
,
2280 tree to_type
, tree parent_convs
, tree other_convs
)
2284 /* See if we are hidden by a parent conversion. */
2285 for (level
= parent_convs
; level
; level
= TREE_CHAIN (level
))
2286 for (probe
= TREE_VALUE (level
); probe
; probe
= TREE_CHAIN (probe
))
2287 if (same_type_p (to_type
, TREE_TYPE (probe
)))
2290 if (virtual_depth
|| virtualness
)
2292 /* In a virtual hierarchy, we could be hidden, or could hide a
2293 conversion function on the other_convs list. */
2294 for (level
= other_convs
; level
; level
= TREE_CHAIN (level
))
2300 if (!(virtual_depth
|| TREE_STATIC (level
)))
2301 /* Neither is morally virtual, so cannot hide each other. */
2304 if (!TREE_VALUE (level
))
2305 /* They evaporated away already. */
2308 they_hide_us
= (virtual_depth
2309 && original_binfo (binfo
, TREE_PURPOSE (level
)));
2310 we_hide_them
= (!they_hide_us
&& TREE_STATIC (level
)
2311 && original_binfo (TREE_PURPOSE (level
), binfo
));
2313 if (!(we_hide_them
|| they_hide_us
))
2314 /* Neither is within the other, so no hiding can occur. */
2317 for (prev
= &TREE_VALUE (level
), other
= *prev
; other
;)
2319 if (same_type_p (to_type
, TREE_TYPE (other
)))
2322 /* We are hidden. */
2327 /* We hide the other one. */
2328 other
= TREE_CHAIN (other
);
2333 prev
= &TREE_CHAIN (other
);
2341 /* Helper for lookup_conversions_r. PARENT_CONVS is a list of lists
2342 of conversion functions, the first slot will be for the current
2343 binfo, if MY_CONVS is non-NULL. CHILD_CONVS is the list of lists
2344 of conversion functions from children of the current binfo,
2345 concatenated with conversions from elsewhere in the hierarchy --
2346 that list begins with OTHER_CONVS. Return a single list of lists
2347 containing only conversions from the current binfo and its
2351 split_conversions (tree my_convs
, tree parent_convs
,
2352 tree child_convs
, tree other_convs
)
2357 /* Remove the original other_convs portion from child_convs. */
2358 for (prev
= NULL
, t
= child_convs
;
2359 t
!= other_convs
; prev
= t
, t
= TREE_CHAIN (t
))
2363 TREE_CHAIN (prev
) = NULL_TREE
;
2365 child_convs
= NULL_TREE
;
2367 /* Attach the child convs to any we had at this level. */
2370 my_convs
= parent_convs
;
2371 TREE_CHAIN (my_convs
) = child_convs
;
2374 my_convs
= child_convs
;
2379 /* Worker for lookup_conversions. Lookup conversion functions in
2380 BINFO and its children. VIRTUAL_DEPTH is nonzero, if BINFO is in a
2381 morally virtual base, and VIRTUALNESS is nonzero, if we've
2382 encountered virtual bases already in the tree walk. PARENT_CONVS
2383 is a list of conversions within parent binfos. OTHER_CONVS are
2384 conversions found elsewhere in the tree. Return the conversions
2385 found within this portion of the graph in CONVS. Return nonzero if
2386 we encountered virtualness. We keep template and non-template
2387 conversions separate, to avoid unnecessary type comparisons.
2389 The located conversion functions are held in lists of lists. The
2390 TREE_VALUE of the outer list is the list of conversion functions
2391 found in a particular binfo. The TREE_PURPOSE of both the outer
2392 and inner lists is the binfo at which those conversions were
2393 found. TREE_STATIC is set for those lists within of morally
2394 virtual binfos. The TREE_VALUE of the inner list is the conversion
2395 function or overload itself. The TREE_TYPE of each inner list node
2396 is the converted-to type. */
2399 lookup_conversions_r (tree binfo
, int virtual_depth
, int virtualness
,
2400 tree parent_convs
, tree other_convs
, tree
*convs
)
2402 int my_virtualness
= 0;
2403 tree my_convs
= NULL_TREE
;
2404 tree child_convs
= NULL_TREE
;
2406 /* If we have no conversion operators, then don't look. */
2407 if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo
)))
2414 if (BINFO_VIRTUAL_P (binfo
))
2417 /* First, locate the unhidden ones at this level. */
2418 if (tree conv
= get_class_binding (BINFO_TYPE (binfo
), conv_op_identifier
))
2419 for (ovl_iterator
iter (conv
); iter
; ++iter
)
2422 tree type
= DECL_CONV_FN_TYPE (fn
);
2424 if (TREE_CODE (fn
) != TEMPLATE_DECL
&& type_uses_auto (type
))
2427 type
= DECL_CONV_FN_TYPE (fn
);
2430 if (check_hidden_convs (binfo
, virtual_depth
, virtualness
,
2431 type
, parent_convs
, other_convs
))
2433 my_convs
= tree_cons (binfo
, fn
, my_convs
);
2434 TREE_TYPE (my_convs
) = type
;
2437 TREE_STATIC (my_convs
) = 1;
2445 parent_convs
= tree_cons (binfo
, my_convs
, parent_convs
);
2447 TREE_STATIC (parent_convs
) = 1;
2450 child_convs
= other_convs
;
2452 /* Now iterate over each base, looking for more conversions. */
2455 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
2458 unsigned base_virtualness
;
2460 base_virtualness
= lookup_conversions_r (base_binfo
,
2461 virtual_depth
, virtualness
,
2462 parent_convs
, child_convs
,
2464 if (base_virtualness
)
2465 my_virtualness
= virtualness
= 1;
2466 child_convs
= chainon (base_convs
, child_convs
);
2469 *convs
= split_conversions (my_convs
, parent_convs
,
2470 child_convs
, other_convs
);
2472 return my_virtualness
;
2475 /* Return a TREE_LIST containing all the non-hidden user-defined
2476 conversion functions for TYPE (and its base-classes). The
2477 TREE_VALUE of each node is the FUNCTION_DECL of the conversion
2478 function. The TREE_PURPOSE is the BINFO from which the conversion
2479 functions in this node were selected. This function is effectively
2480 performing a set of member lookups as lookup_fnfield does, but
2481 using the type being converted to as the unique key, rather than the
2485 lookup_conversions (tree type
)
2489 complete_type (type
);
2490 if (!CLASS_TYPE_P (type
) || !TYPE_BINFO (type
))
2493 lookup_conversions_r (TYPE_BINFO (type
), 0, 0, NULL_TREE
, NULL_TREE
, &convs
);
2495 tree list
= NULL_TREE
;
2497 /* Flatten the list-of-lists */
2498 for (; convs
; convs
= TREE_CHAIN (convs
))
2502 for (probe
= TREE_VALUE (convs
); probe
; probe
= next
)
2504 next
= TREE_CHAIN (probe
);
2506 TREE_CHAIN (probe
) = list
;
2514 /* Returns the binfo of the first direct or indirect virtual base derived
2515 from BINFO, or NULL if binfo is not via virtual. */
2518 binfo_from_vbase (tree binfo
)
2520 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2522 if (BINFO_VIRTUAL_P (binfo
))
2528 /* Returns the binfo of the first direct or indirect virtual base derived
2529 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2533 binfo_via_virtual (tree binfo
, tree limit
)
2535 if (limit
&& !CLASSTYPE_VBASECLASSES (limit
))
2536 /* LIMIT has no virtual bases, so BINFO cannot be via one. */
2539 for (; binfo
&& !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), limit
);
2540 binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2542 if (BINFO_VIRTUAL_P (binfo
))
2548 /* BINFO is for a base class in some hierarchy. Return true iff it is a
2552 binfo_direct_p (tree binfo
)
2554 tree d_binfo
= BINFO_INHERITANCE_CHAIN (binfo
);
2555 if (BINFO_INHERITANCE_CHAIN (d_binfo
))
2556 /* A second inheritance chain means indirect. */
2558 if (!BINFO_VIRTUAL_P (binfo
))
2559 /* Non-virtual, so only one inheritance chain means direct. */
2561 /* A virtual base looks like a direct base, so we need to look through the
2562 direct bases to see if it's there. */
2564 for (int i
= 0; BINFO_BASE_ITERATE (d_binfo
, i
, b_binfo
); ++i
)
2565 if (b_binfo
== binfo
)
2570 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2571 Find the equivalent binfo within whatever graph HERE is located.
2572 This is the inverse of original_binfo. */
2575 copied_binfo (tree binfo
, tree here
)
2577 tree result
= NULL_TREE
;
2579 if (BINFO_VIRTUAL_P (binfo
))
2583 for (t
= here
; BINFO_INHERITANCE_CHAIN (t
);
2584 t
= BINFO_INHERITANCE_CHAIN (t
))
2587 result
= binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (t
));
2589 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2595 cbinfo
= copied_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2596 for (ix
= 0; BINFO_BASE_ITERATE (cbinfo
, ix
, base_binfo
); ix
++)
2597 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo
), BINFO_TYPE (binfo
)))
2599 result
= base_binfo
;
2605 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here
), BINFO_TYPE (binfo
)));
2609 gcc_assert (result
);
2614 binfo_for_vbase (tree base
, tree t
)
2618 vec
<tree
, va_gc
> *vbases
;
2620 for (vbases
= CLASSTYPE_VBASECLASSES (t
), ix
= 0;
2621 vec_safe_iterate (vbases
, ix
, &binfo
); ix
++)
2622 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), base
))
2627 /* BINFO is some base binfo of HERE, within some other
2628 hierarchy. Return the equivalent binfo, but in the hierarchy
2629 dominated by HERE. This is the inverse of copied_binfo. If BINFO
2630 is not a base binfo of HERE, returns NULL_TREE. */
2633 original_binfo (tree binfo
, tree here
)
2637 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo
), BINFO_TYPE (here
)))
2639 else if (BINFO_VIRTUAL_P (binfo
))
2640 result
= (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here
))
2641 ? binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (here
))
2643 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2647 base_binfos
= original_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2653 for (ix
= 0; (base_binfo
= BINFO_BASE_BINFO (base_binfos
, ix
)); ix
++)
2654 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo
),
2655 BINFO_TYPE (binfo
)))
2657 result
= base_binfo
;
2666 /* True iff TYPE has any dependent bases (and therefore we can't say
2667 definitively that another class is not a base of an instantiation of
2671 any_dependent_bases_p (tree type
)
2673 if (!type
|| !CLASS_TYPE_P (type
) || !uses_template_parms (type
))
2676 /* If we haven't set TYPE_BINFO yet, we don't know anything about the bases.
2677 Return false because in this situation we aren't actually looking up names
2678 in the scope of the class, so it doesn't matter whether it has dependent
2680 if (!TYPE_BINFO (type
))
2685 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_BINFOS (TYPE_BINFO (type
)), i
, base_binfo
)
2686 if (BINFO_DEPENDENT_BASE_P (base_binfo
))