1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* For use with name_hint. */
22 #define INCLUDE_UNIQUE_PTR
24 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "tree-diagnostic.h"
28 #include "langhooks-def.h"
30 #include "cxx-pretty-print.h"
31 #include "tree-pretty-print.h"
32 #include "gimple-pretty-print.h"
33 #include "c-family/c-objc.h"
35 #include "internal-fn.h"
36 #include "gcc-rich-location.h"
37 #include "cp-name-hint.h"
39 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
40 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
42 /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
43 dump C++ ASTs as strings. It is mostly used only by the various
44 tree -> string functions that are occasionally called from the
45 debugger or by the front-end for things like
46 __PRETTY_FUNCTION__. */
47 static cxx_pretty_printer actual_pretty_printer
;
48 static cxx_pretty_printer
* const cxx_pp
= &actual_pretty_printer
;
50 /* Translate if being used for diagnostics, but not for dump files or
52 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
54 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
56 static const char *args_to_string (tree
, int);
57 static const char *code_to_string (enum tree_code
);
58 static const char *cv_to_string (tree
, int);
59 static const char *decl_to_string (tree
, int);
60 static const char *fndecl_to_string (tree
, int);
61 static const char *op_to_string (bool, enum tree_code
);
62 static const char *parm_to_string (int);
63 static const char *type_to_string (tree
, int, bool, bool *, bool);
65 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
66 static void dump_type (cxx_pretty_printer
*, tree
, int);
67 static void dump_typename (cxx_pretty_printer
*, tree
, int);
68 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
69 static void dump_decl (cxx_pretty_printer
*, tree
, int);
70 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
71 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
72 static void dump_expr (cxx_pretty_printer
*, tree
, int);
73 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
74 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
75 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
76 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
77 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
78 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
79 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
80 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
81 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
82 static void dump_global_iord (cxx_pretty_printer
*, tree
);
83 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
84 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
85 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
86 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
87 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
88 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
89 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
91 static void dump_scope (cxx_pretty_printer
*, tree
, int);
92 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
93 static int get_non_default_template_args_count (tree
, int);
94 static const char *function_category (tree
);
95 static void maybe_print_constexpr_context (diagnostic_context
*);
96 static void maybe_print_instantiation_context (diagnostic_context
*);
97 static void print_instantiation_full_context (diagnostic_context
*);
98 static void print_instantiation_partial_context (diagnostic_context
*,
101 static void maybe_print_constraint_context (diagnostic_context
*);
102 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
103 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
105 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
106 int, bool, bool, bool, bool *, const char **);
108 /* Struct for handling %H or %I, which require delaying printing the
109 type until a postprocessing stage. */
111 class deferred_printed_type
114 deferred_printed_type ()
115 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
118 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
120 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
124 gcc_assert (buffer_ptr
);
127 /* The tree is not GTY-marked: they are only non-NULL within a
128 call to pp_format. */
130 const char **m_buffer_ptr
;
135 /* Subclass of format_postprocessor for the C++ frontend.
136 This handles the %H and %I formatting codes, printing them
137 in a postprocessing phase (since they affect each other). */
139 class cxx_format_postprocessor
: public format_postprocessor
142 cxx_format_postprocessor ()
143 : m_type_a (), m_type_b ()
146 format_postprocessor
*clone() const FINAL OVERRIDE
148 return new cxx_format_postprocessor ();
151 void handle (pretty_printer
*pp
) FINAL OVERRIDE
;
153 deferred_printed_type m_type_a
;
154 deferred_printed_type m_type_b
;
157 /* CONTEXT->printer is a basic pretty printer that was constructed
158 presumably by diagnostic_initialize(), called early in the
159 compiler's initialization process (in general_init) Before the FE
160 is initialized. This (C++) FE-specific diagnostic initializer is
161 thus replacing the basic pretty printer with one that has C++-aware
165 cxx_initialize_diagnostics (diagnostic_context
*context
)
167 pretty_printer
*base
= context
->printer
;
168 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
169 context
->printer
= new (pp
) cxx_pretty_printer ();
171 /* It is safe to free this object because it was previously XNEW()'d. */
172 base
->~pretty_printer ();
175 c_common_diagnostics_set_defaults (context
);
176 diagnostic_starter (context
) = cp_diagnostic_starter
;
177 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
178 diagnostic_format_decoder (context
) = cp_printer
;
179 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
182 /* Dump a scope, if deemed necessary. */
185 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
187 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
189 if (scope
== NULL_TREE
)
192 /* Enum values within an unscoped enum will be CONST_DECL with an
193 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
194 ENUMERAL_TYPE, so as to print any enclosing namespace. */
195 if (UNSCOPED_ENUM_P (scope
))
196 scope
= CP_TYPE_CONTEXT (scope
);
198 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
200 if (scope
!= global_namespace
)
202 dump_decl (pp
, scope
, f
);
203 pp_cxx_colon_colon (pp
);
206 else if (AGGREGATE_TYPE_P (scope
)
207 || SCOPED_ENUM_P (scope
))
209 dump_type (pp
, scope
, f
);
210 pp_cxx_colon_colon (pp
);
212 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
214 if (DECL_USE_TEMPLATE (scope
))
215 f
|= TFF_NO_FUNCTION_ARGUMENTS
;
216 dump_function_decl (pp
, scope
, f
);
217 pp_cxx_colon_colon (pp
);
221 /* Dump the template ARGument under control of FLAGS. */
224 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
226 if (ARGUMENT_PACK_P (arg
))
227 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
228 /* No default args in argument packs. */
229 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
230 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
231 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
234 if (TREE_CODE (arg
) == TREE_LIST
)
235 arg
= TREE_VALUE (arg
);
237 /* Strip implicit conversions. */
238 while (CONVERT_EXPR_P (arg
))
239 arg
= TREE_OPERAND (arg
, 0);
241 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
245 /* Count the number of template arguments ARGS whose value does not
246 match the (optional) default template parameter in PARAMS */
249 get_non_default_template_args_count (tree args
, int flags
)
251 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
253 if (/* We use this flag when generating debug information. We don't
254 want to expand templates at this point, for this may generate
255 new decls, which gets decl counts out of sync, which may in
256 turn cause codegen differences between compilations with and
258 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
259 || !flag_pretty_templates
)
262 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
265 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
269 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
271 int n
= get_non_default_template_args_count (args
, flags
);
275 for (i
= 0; i
< n
; ++i
)
277 tree arg
= TREE_VEC_ELT (args
, i
);
279 /* Only print a comma if we know there is an argument coming. In
280 the case of an empty template argument pack, no actual
281 argument will be printed. */
283 && (!ARGUMENT_PACK_P (arg
)
284 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
285 pp_separate_with_comma (pp
);
287 dump_template_argument (pp
, arg
, flags
);
292 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
295 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
300 if (parm
== error_mark_node
)
303 p
= TREE_VALUE (parm
);
304 a
= TREE_PURPOSE (parm
);
306 if (TREE_CODE (p
) == TYPE_DECL
)
308 if (flags
& TFF_DECL_SPECIFIERS
)
310 pp_cxx_ws_string (pp
, "class");
311 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
312 pp_cxx_ws_string (pp
, "...");
314 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
316 else if (DECL_NAME (p
))
317 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
319 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
322 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
324 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
326 pp_cxx_whitespace (pp
);
328 pp_cxx_whitespace (pp
);
329 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
330 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
332 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
336 /* Dump, under control of FLAGS, a template-parameter-list binding.
337 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
341 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
342 vec
<tree
, va_gc
> *typenames
)
344 bool need_semicolon
= false;
350 tree p
= TREE_VALUE (parms
);
351 int lvl
= TMPL_PARMS_DEPTH (parms
);
354 tree lvl_args
= NULL_TREE
;
356 /* Don't crash if we had an invalid argument list. */
357 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
358 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
360 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
362 tree arg
= NULL_TREE
;
364 /* Don't crash if we had an invalid argument list. */
365 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
366 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
369 pp_separate_with_semicolon (pp
);
370 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
371 TFF_PLAIN_IDENTIFIER
);
372 pp_cxx_whitespace (pp
);
374 pp_cxx_whitespace (pp
);
377 if (ARGUMENT_PACK_P (arg
))
378 pp_cxx_left_brace (pp
);
379 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
380 if (ARGUMENT_PACK_P (arg
))
381 pp_cxx_right_brace (pp
);
384 pp_string (pp
, M_("<missing>"));
387 need_semicolon
= true;
390 parms
= TREE_CHAIN (parms
);
393 /* Don't bother with typenames for a partial instantiation. */
394 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
397 /* Don't try to print typenames when we're processing a clone. */
398 if (current_function_decl
399 && !DECL_LANG_SPECIFIC (current_function_decl
))
402 /* Don't try to do this once cgraph starts throwing away front-end
407 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
410 pp_separate_with_semicolon (pp
);
411 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
412 pp_cxx_whitespace (pp
);
414 pp_cxx_whitespace (pp
);
415 push_deferring_access_checks (dk_no_check
);
416 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
417 pop_deferring_access_checks ();
418 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
419 pp_simple_type_specifier doesn't know about it. */
420 t
= strip_typedefs (t
, NULL
, STF_USER_VISIBLE
);
421 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
425 /* Dump a human-readable equivalent of the alias template
426 specialization of T. */
429 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
431 gcc_assert (alias_template_specialization_p (t
, nt_opaque
));
433 tree decl
= TYPE_NAME (t
);
434 if (!(flags
& TFF_UNQUALIFIED_NAME
))
435 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
436 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
437 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
439 flags
& ~TFF_TEMPLATE_HEADER
);
442 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
446 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
451 /* Don't print e.g. "struct mytypedef". */
452 if (TYPE_P (t
) && typedef_variant_p (t
))
454 tree decl
= TYPE_NAME (t
);
455 if ((flags
& TFF_CHASE_TYPEDEF
)
456 || DECL_SELF_REFERENCE_P (decl
)
457 || (!flag_pretty_templates
458 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
460 unsigned int stf_flags
= (!(pp
->flags
& pp_c_flag_gnu_v3
)
461 ? STF_USER_VISIBLE
: 0);
462 t
= strip_typedefs (t
, NULL
, stf_flags
);
464 else if (alias_template_specialization_p (t
, nt_opaque
))
466 dump_alias_template_specialization (pp
, t
, flags
);
469 else if (same_type_p (t
, TREE_TYPE (decl
)))
473 pp_cxx_cv_qualifier_seq (pp
, t
);
474 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
479 if (TYPE_PTRMEMFUNC_P (t
))
482 switch (TREE_CODE (t
))
485 if (t
== init_list_type_node
)
486 pp_string (pp
, M_("<brace-enclosed initializer list>"));
487 else if (t
== unknown_type_node
)
488 pp_string (pp
, M_("<unresolved overloaded function type>"));
491 pp_cxx_cv_qualifier_seq (pp
, t
);
492 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
497 /* A list of function parms. */
498 dump_parameters (pp
, t
, flags
);
501 case IDENTIFIER_NODE
:
502 pp_cxx_tree_identifier (pp
, t
);
506 dump_type (pp
, BINFO_TYPE (t
), flags
);
512 dump_aggr_type (pp
, t
, flags
);
516 if (flags
& TFF_CHASE_TYPEDEF
)
518 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
519 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
526 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
535 case FIXED_POINT_TYPE
:
536 pp_type_specifier_seq (pp
, t
);
539 case TEMPLATE_TEMPLATE_PARM
:
540 /* For parameters inside template signature. */
541 if (TYPE_IDENTIFIER (t
))
542 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
544 pp_cxx_canonical_template_parameter (pp
, t
);
547 case BOUND_TEMPLATE_TEMPLATE_PARM
:
549 tree args
= TYPE_TI_ARGS (t
);
550 pp_cxx_cv_qualifier_seq (pp
, t
);
551 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
552 pp_cxx_begin_template_argument_list (pp
);
553 dump_template_argument_list (pp
, args
, flags
);
554 pp_cxx_end_template_argument_list (pp
);
558 case TEMPLATE_TYPE_PARM
:
559 pp_cxx_cv_qualifier_seq (pp
, t
);
560 if (template_placeholder_p (t
))
562 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
563 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
564 pp_string (pp
, "<...auto...>");
566 else if (TYPE_IDENTIFIER (t
))
567 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
569 pp_cxx_canonical_template_parameter
570 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
571 /* If this is a constrained placeholder, add the requirements. */
572 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
573 pp_cxx_constrained_type_spec (pp
, c
);
576 /* This is not always necessary for pointers and such, but doing this
577 reduces code size. */
586 dump_type_prefix (pp
, t
, flags
);
587 dump_type_suffix (pp
, t
, flags
);
591 if (! (flags
& TFF_CHASE_TYPEDEF
)
592 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
594 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
597 pp_cxx_cv_qualifier_seq (pp
, t
);
598 pp_cxx_ws_string (pp
,
599 TYPENAME_IS_ENUM_P (t
) ? "enum"
600 : TYPENAME_IS_CLASS_P (t
) ? "class"
602 dump_typename (pp
, t
, flags
);
605 case UNBOUND_CLASS_TEMPLATE
:
606 if (! (flags
& TFF_UNQUALIFIED_NAME
))
608 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
609 pp_cxx_colon_colon (pp
);
611 pp_cxx_ws_string (pp
, "template");
612 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
616 pp_cxx_ws_string (pp
, "__typeof__");
617 pp_cxx_whitespace (pp
);
618 pp_cxx_left_paren (pp
);
619 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
620 pp_cxx_right_paren (pp
);
623 case UNDERLYING_TYPE
:
624 pp_cxx_ws_string (pp
, "__underlying_type");
625 pp_cxx_whitespace (pp
);
626 pp_cxx_left_paren (pp
);
627 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
628 pp_cxx_right_paren (pp
);
631 case TYPE_PACK_EXPANSION
:
632 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
633 pp_cxx_ws_string (pp
, "...");
636 case TYPE_ARGUMENT_PACK
:
637 dump_template_argument (pp
, t
, flags
);
641 pp_cxx_ws_string (pp
, "decltype");
642 pp_cxx_whitespace (pp
);
643 pp_cxx_left_paren (pp
);
644 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
645 pp_cxx_right_paren (pp
);
649 pp_string (pp
, "std::nullptr_t");
653 pp_unsupported_tree (pp
, t
);
657 pp_string (pp
, M_("<type error>"));
662 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
666 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
668 tree ctx
= TYPE_CONTEXT (t
);
670 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
671 dump_typename (pp
, ctx
, flags
);
673 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
674 pp_cxx_colon_colon (pp
);
675 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
678 /* Return the name of the supplied aggregate, or enumeral type. */
681 class_key_or_enum_as_string (tree t
)
683 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
685 if (SCOPED_ENUM_P (t
))
690 else if (TREE_CODE (t
) == UNION_TYPE
)
692 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
698 /* Print out a class declaration T under the control of FLAGS,
699 in the form `class foo'. */
702 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
704 const char *variety
= class_key_or_enum_as_string (t
);
708 pp_cxx_cv_qualifier_seq (pp
, t
);
710 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
711 pp_cxx_ws_string (pp
, variety
);
713 tree decl
= TYPE_NAME (t
);
717 typdef
= (!DECL_ARTIFICIAL (decl
)
718 /* An alias specialization is not considered to be a
720 && !alias_template_specialization_p (t
, nt_opaque
));
723 && ((flags
& TFF_CHASE_TYPEDEF
)
724 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (decl
)
725 && DECL_TEMPLATE_INFO (decl
))))
726 || DECL_SELF_REFERENCE_P (decl
))
728 t
= TYPE_MAIN_VARIANT (t
);
729 decl
= TYPE_NAME (t
);
733 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
734 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
735 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
736 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
738 if (! (flags
& TFF_UNQUALIFIED_NAME
))
739 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
| TFF_SCOPE
);
740 flags
&= ~TFF_UNQUALIFIED_NAME
;
743 /* Because the template names are mangled, we have to locate
744 the most general template, and use that name. */
745 tree tpl
= TYPE_TI_TEMPLATE (t
);
747 while (DECL_TEMPLATE_INFO (tpl
))
748 tpl
= DECL_TI_TEMPLATE (tpl
);
753 if (LAMBDA_TYPE_P (t
))
755 /* A lambda's "type" is essentially its signature. */
756 pp_string (pp
, M_("<lambda"));
757 if (lambda_function (t
))
759 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
763 else if (!decl
|| IDENTIFIER_ANON_P (DECL_NAME (decl
)))
765 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
766 pp_string (pp
, M_("<unnamed>"));
768 pp_printf (pp
, M_("<unnamed %s>"), variety
);
771 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
774 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
775 !CLASSTYPE_USE_TEMPLATE (t
),
776 flags
& ~TFF_TEMPLATE_HEADER
);
779 /* Dump into the obstack the initial part of the output for a given type.
780 This is necessary when dealing with things like functions returning
783 return type of `int (* fee ())()': pointer -> function -> int. Both
784 pointer (and reference and offset) and function (and member) types must
785 deal with prefix and suffix.
787 Arrays must also do this for DECL nodes, like int a[], and for things like
791 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
793 if (TYPE_PTRMEMFUNC_P (t
))
795 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
799 switch (TREE_CODE (t
))
804 tree sub
= TREE_TYPE (t
);
806 dump_type_prefix (pp
, sub
, flags
);
807 if (TREE_CODE (sub
) == ARRAY_TYPE
808 || TREE_CODE (sub
) == FUNCTION_TYPE
)
810 pp_cxx_whitespace (pp
);
811 pp_cxx_left_paren (pp
);
812 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
816 else if (TYPE_REF_P (t
))
818 if (TYPE_REF_IS_RVALUE (t
))
819 pp_ampersand_ampersand (pp
);
823 pp
->padding
= pp_before
;
824 pp_cxx_cv_qualifier_seq (pp
, t
);
830 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
831 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
834 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
835 pp_cxx_left_paren (pp
);
836 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
837 pp_cxx_colon_colon (pp
);
840 pp_cxx_cv_qualifier_seq (pp
, t
);
841 pp
->padding
= pp_before
;
844 /* This can be reached without a pointer when dealing with
845 templates, e.g. std::is_function. */
847 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
851 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
853 pp_cxx_left_paren (pp
);
854 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
855 pp_cxx_colon_colon (pp
);
859 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
863 case IDENTIFIER_NODE
:
868 case TEMPLATE_TYPE_PARM
:
869 case TEMPLATE_TEMPLATE_PARM
:
870 case BOUND_TEMPLATE_TEMPLATE_PARM
:
881 case UNDERLYING_TYPE
:
883 case TYPE_PACK_EXPANSION
:
884 case FIXED_POINT_TYPE
:
886 dump_type (pp
, t
, flags
);
887 pp
->padding
= pp_before
;
891 pp_unsupported_tree (pp
, t
);
894 pp_string (pp
, M_("<typeprefixerror>"));
899 /* Dump the suffix of type T, under control of FLAGS. This is the part
900 which appears after the identifier (or function parms). */
903 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
905 if (TYPE_PTRMEMFUNC_P (t
))
906 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
908 switch (TREE_CODE (t
))
913 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
914 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
915 pp_cxx_right_paren (pp
);
916 if (TREE_CODE (t
) == POINTER_TYPE
)
917 flags
|= TFF_POINTER
;
918 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
925 if (TREE_CODE (t
) == METHOD_TYPE
)
926 /* Can only be reached through a pointer. */
927 pp_cxx_right_paren (pp
);
928 arg
= TYPE_ARG_TYPES (t
);
929 if (TREE_CODE (t
) == METHOD_TYPE
)
930 arg
= TREE_CHAIN (arg
);
932 /* Function pointers don't have default args. Not in standard C++,
933 anyway; they may in g++, but we'll just pretend otherwise. */
934 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
936 pp
->padding
= pp_before
;
937 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
938 TREE_CODE (t
) == FUNCTION_TYPE
939 && (flags
& TFF_POINTER
));
940 dump_ref_qualifier (pp
, t
, flags
);
941 if (tx_safe_fn_type_p (t
))
942 pp_cxx_ws_string (pp
, "transaction_safe");
943 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
944 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
950 pp_cxx_left_bracket (pp
);
951 if (tree dtype
= TYPE_DOMAIN (t
))
953 tree max
= TYPE_MAX_VALUE (dtype
);
954 /* Zero-length arrays have an upper bound of SIZE_MAX. */
955 if (integer_all_onesp (max
))
956 pp_character (pp
, '0');
957 else if (tree_fits_shwi_p (max
))
958 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
962 if (TREE_CODE (max
) == SAVE_EXPR
)
963 max
= TREE_OPERAND (max
, 0);
964 if (TREE_CODE (max
) == MINUS_EXPR
965 || TREE_CODE (max
) == PLUS_EXPR
)
967 max
= TREE_OPERAND (max
, 0);
968 while (CONVERT_EXPR_P (max
))
969 max
= TREE_OPERAND (max
, 0);
972 max
= fold_build2_loc (input_location
,
973 PLUS_EXPR
, dtype
, max
,
974 build_int_cst (dtype
, 1));
975 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
978 pp_cxx_right_bracket (pp
);
979 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
983 case IDENTIFIER_NODE
:
988 case TEMPLATE_TYPE_PARM
:
989 case TEMPLATE_TEMPLATE_PARM
:
990 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1001 case UNDERLYING_TYPE
:
1003 case TYPE_PACK_EXPANSION
:
1004 case FIXED_POINT_TYPE
:
1009 pp_unsupported_tree (pp
, t
);
1011 /* Don't mark it here, we should have already done in
1012 dump_type_prefix. */
1018 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1020 const char *p
= NULL
;
1022 if (DECL_GLOBAL_CTOR_P (t
))
1023 p
= M_("(static initializers for %s)");
1024 else if (DECL_GLOBAL_DTOR_P (t
))
1025 p
= M_("(static destructors for %s)");
1029 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1033 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1035 if (template_parm_object_p (t
))
1036 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1038 if (flags
& TFF_DECL_SPECIFIERS
)
1040 if (concept_definition_p (t
))
1041 pp_cxx_ws_string (pp
, "concept");
1042 else if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1043 pp_cxx_ws_string (pp
, "constexpr");
1045 if (!standard_concept_p (t
))
1046 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1047 pp_maybe_space (pp
);
1049 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1050 && TREE_CODE (t
) != PARM_DECL
1051 && (!DECL_INITIAL (t
)
1052 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1053 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1054 flags
&= ~TFF_UNQUALIFIED_NAME
;
1055 if ((flags
& TFF_DECL_SPECIFIERS
)
1056 && DECL_TEMPLATE_PARM_P (t
)
1057 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1058 pp_string (pp
, "...");
1061 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1064 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1065 pp_string (pp
, " capture>");
1068 dump_decl (pp
, DECL_NAME (t
), flags
);
1070 else if (DECL_DECOMPOSITION_P (t
))
1071 pp_string (pp
, M_("<structured bindings>"));
1073 pp_string (pp
, M_("<anonymous>"));
1074 if (flags
& TFF_DECL_SPECIFIERS
)
1075 dump_type_suffix (pp
, type
, flags
);
1078 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1081 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1083 /* These special cases are duplicated here so that other functions
1084 can feed identifiers to error and get them demangled properly. */
1085 if (IDENTIFIER_CONV_OP_P (t
))
1087 pp_cxx_ws_string (pp
, "operator");
1088 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1089 dump_type (pp
, TREE_TYPE (t
), flags
);
1092 if (dguide_name_p (t
))
1094 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1095 TFF_UNQUALIFIED_NAME
);
1099 const char *str
= IDENTIFIER_POINTER (t
);
1100 if (!strncmp (str
, "_ZGR", 4))
1102 pp_cxx_ws_string (pp
, "<temporary>");
1106 pp_cxx_tree_identifier (pp
, t
);
1109 /* Dump a human readable string for the decl T under control of FLAGS. */
1112 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1117 /* If doing Objective-C++, give Objective-C a chance to demangle
1118 Objective-C method names. */
1119 if (c_dialect_objc ())
1121 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1124 pp_string (pp
, demangled
);
1129 switch (TREE_CODE (t
))
1132 /* Don't say 'typedef class A' */
1133 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1135 if ((flags
& TFF_DECL_SPECIFIERS
)
1136 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1138 /* Say `class T' not just `T'. */
1139 pp_cxx_ws_string (pp
, "class");
1141 /* Emit the `...' for a parameter pack. */
1142 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1143 pp_cxx_ws_string (pp
, "...");
1146 dump_type (pp
, TREE_TYPE (t
), flags
);
1149 if (TYPE_DECL_ALIAS_P (t
)
1150 && (flags
& TFF_DECL_SPECIFIERS
1151 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1153 pp_cxx_ws_string (pp
, "using");
1154 dump_decl (pp
, DECL_NAME (t
), flags
);
1155 pp_cxx_whitespace (pp
);
1156 pp_cxx_ws_string (pp
, "=");
1157 pp_cxx_whitespace (pp
);
1158 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1159 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1163 if ((flags
& TFF_DECL_SPECIFIERS
)
1164 && !DECL_SELF_REFERENCE_P (t
))
1165 pp_cxx_ws_string (pp
, "typedef");
1166 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1167 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1172 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1174 pp_string (pp
, M_("vtable for "));
1175 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1176 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1182 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1184 /* Handle variable template specializations. */
1186 && DECL_LANG_SPECIFIC (t
)
1187 && DECL_TEMPLATE_INFO (t
)
1188 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1190 pp_cxx_begin_template_argument_list (pp
);
1191 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1192 dump_template_argument_list (pp
, args
, flags
);
1193 pp_cxx_end_template_argument_list (pp
);
1198 pp_string (pp
, M_("<return value> "));
1199 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1202 case NAMESPACE_DECL
:
1203 if (flags
& TFF_DECL_SPECIFIERS
)
1204 pp
->declaration (t
);
1207 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1208 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1209 flags
&= ~TFF_UNQUALIFIED_NAME
;
1210 if (DECL_NAME (t
) == NULL_TREE
)
1212 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1213 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1215 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1218 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1223 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1224 pp_cxx_colon_colon (pp
);
1225 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1229 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1230 pp_cxx_left_bracket (pp
);
1231 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1232 pp_cxx_right_bracket (pp
);
1235 /* So that we can do dump_decl on an aggr type. */
1239 dump_type (pp
, t
, flags
);
1243 /* This is a pseudo destructor call which has not been folded into
1244 a PSEUDO_DTOR_EXPR yet. */
1245 pp_cxx_complement (pp
);
1246 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1253 case IDENTIFIER_NODE
:
1254 dump_decl_name (pp
, t
, flags
);
1258 if (!OVL_SINGLE_P (t
))
1260 tree ctx
= ovl_scope (t
);
1261 if (ctx
!= global_namespace
)
1264 dump_type (pp
, ctx
, flags
);
1266 dump_decl (pp
, ctx
, flags
);
1267 pp_cxx_colon_colon (pp
);
1269 dump_decl (pp
, OVL_NAME (t
), flags
);
1273 /* If there's only one function, just treat it like an ordinary
1279 if (! DECL_LANG_SPECIFIC (t
))
1281 if (DECL_ABSTRACT_ORIGIN (t
)
1282 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1283 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1285 dump_function_name (pp
, t
, flags
);
1287 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1288 dump_global_iord (pp
, t
);
1290 dump_function_decl (pp
, t
, flags
);
1294 dump_template_decl (pp
, t
, flags
);
1298 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1302 pp_string (pp
, "<wildcard>");
1305 case TEMPLATE_ID_EXPR
:
1307 tree name
= TREE_OPERAND (t
, 0);
1308 tree args
= TREE_OPERAND (t
, 1);
1310 if (!identifier_p (name
))
1311 name
= OVL_NAME (name
);
1312 dump_decl (pp
, name
, flags
);
1313 pp_cxx_begin_template_argument_list (pp
);
1314 if (args
== error_mark_node
)
1315 pp_string (pp
, M_("<template arguments error>"));
1317 dump_template_argument_list
1318 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1319 pp_cxx_end_template_argument_list (pp
);
1324 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1328 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1329 || (DECL_INITIAL (t
) &&
1330 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1331 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1332 else if (DECL_NAME (t
))
1333 dump_decl (pp
, DECL_NAME (t
), flags
);
1334 else if (DECL_INITIAL (t
))
1335 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1337 pp_string (pp
, M_("<enumerator>"));
1342 pp_cxx_ws_string (pp
, "using");
1343 tree scope
= USING_DECL_SCOPE (t
);
1344 bool variadic
= false;
1345 if (PACK_EXPANSION_P (scope
))
1347 scope
= PACK_EXPANSION_PATTERN (scope
);
1350 dump_type (pp
, scope
, flags
);
1351 pp_cxx_colon_colon (pp
);
1352 dump_decl (pp
, DECL_NAME (t
), flags
);
1354 pp_cxx_ws_string (pp
, "...");
1359 pp
->declaration (t
);
1363 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1366 case NON_DEPENDENT_EXPR
:
1367 dump_expr (pp
, t
, flags
);
1370 case TEMPLATE_TYPE_PARM
:
1371 if (flags
& TFF_DECL_SPECIFIERS
)
1372 pp
->declaration (t
);
1377 case UNBOUND_CLASS_TEMPLATE
:
1378 case TYPE_PACK_EXPANSION
:
1380 dump_type (pp
, t
, flags
);
1384 pp_unsupported_tree (pp
, t
);
1388 pp_string (pp
, M_("<declaration error>"));
1393 /* Dump a template declaration T under control of FLAGS. This means the
1394 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1397 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1399 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1403 if (flags
& TFF_TEMPLATE_HEADER
)
1405 for (parms
= orig_parms
= nreverse (orig_parms
);
1407 parms
= TREE_CHAIN (parms
))
1409 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1410 int len
= TREE_VEC_LENGTH (inner_parms
);
1414 /* Skip over the dummy template levels of a template template
1416 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1420 pp_cxx_ws_string (pp
, "template");
1421 pp_cxx_begin_template_argument_list (pp
);
1423 /* If we've shown the template prefix, we'd better show the
1424 parameters' and decl's type too. */
1425 flags
|= TFF_DECL_SPECIFIERS
;
1427 for (i
= 0; i
< len
; i
++)
1430 pp_separate_with_comma (pp
);
1431 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1434 pp_cxx_end_template_argument_list (pp
);
1435 pp_cxx_whitespace (pp
);
1437 nreverse(orig_parms
);
1439 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1441 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1442 pp_cxx_ws_string (pp
, "class");
1444 /* If this is a parameter pack, print the ellipsis. */
1445 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1446 pp_cxx_ws_string (pp
, "...");
1449 /* Only print the requirements if we're also printing
1450 the template header. */
1452 if (tree ci
= get_constraints (t
))
1453 if (check_constraint_info (ci
))
1454 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1456 pp_cxx_requires_clause (pp
, reqs
);
1457 pp_cxx_whitespace (pp
);
1462 if (DECL_CLASS_TEMPLATE_P (t
))
1463 dump_type (pp
, TREE_TYPE (t
),
1464 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1465 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1466 else if (DECL_TEMPLATE_RESULT (t
)
1467 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1468 /* Alias template. */
1469 || DECL_TYPE_TEMPLATE_P (t
)
1470 /* Concept definition. &*/
1471 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1472 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1475 gcc_assert (TREE_TYPE (t
));
1476 switch (NEXT_CODE (t
))
1480 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1483 /* This case can occur with some invalid code. */
1484 dump_type (pp
, TREE_TYPE (t
),
1485 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1486 | (flags
& TFF_DECL_SPECIFIERS
1487 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1492 /* find_typenames looks through the type of the function template T
1493 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1496 struct find_typenames_t
1498 hash_set
<tree
> *p_set
;
1499 vec
<tree
, va_gc
> *typenames
;
1503 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1505 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1506 tree mv
= NULL_TREE
;
1508 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1509 /* Add the type of the typedef without any additional cv-quals. */
1510 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1511 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1512 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1513 /* Add the typename without any cv-qualifiers. */
1514 mv
= TYPE_MAIN_VARIANT (*tp
);
1516 if (PACK_EXPANSION_P (*tp
))
1518 /* Don't mess with parameter packs since we don't remember
1519 the pack expansion context for a particular typename. */
1520 *walk_subtrees
= false;
1524 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1525 vec_safe_push (d
->typenames
, mv
);
1530 static vec
<tree
, va_gc
> *
1531 find_typenames (tree t
)
1533 struct find_typenames_t ft
;
1534 ft
.p_set
= new hash_set
<tree
>;
1535 ft
.typenames
= NULL
;
1536 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1537 find_typenames_r
, &ft
, ft
.p_set
);
1539 return ft
.typenames
;
1542 /* Output the "[with ...]" clause for a template instantiation T iff
1543 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1544 formatting a deduction/substitution diagnostic rather than an
1548 dump_substitution (cxx_pretty_printer
*pp
,
1549 tree t
, tree template_parms
, tree template_args
,
1552 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1553 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1555 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1556 pp_cxx_whitespace (pp
);
1557 pp_cxx_left_bracket (pp
);
1558 pp
->translate_string ("with");
1559 pp_cxx_whitespace (pp
);
1560 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1561 pp_cxx_right_bracket (pp
);
1565 /* Dump the lambda function FN including its 'mutable' qualifier and any
1566 template bindings. */
1569 dump_lambda_function (cxx_pretty_printer
*pp
,
1570 tree fn
, tree template_parms
, tree template_args
,
1573 /* A lambda's signature is essentially its "type". */
1574 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1575 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1577 pp
->padding
= pp_before
;
1578 pp_c_ws_string (pp
, "mutable");
1580 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1583 /* Pretty print a function decl. There are several ways we want to print a
1584 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1585 As error can only apply the '#' flag once to give 0 and 1 for V, there
1586 is %D which doesn't print the throw specs, and %F which does. */
1589 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1593 tree cname
= NULL_TREE
;
1594 tree template_args
= NULL_TREE
;
1595 tree template_parms
= NULL_TREE
;
1596 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1597 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1600 tree ret
= NULL_TREE
;
1602 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1603 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1604 t
= DECL_TEMPLATE_RESULT (t
);
1606 /* Save the exceptions, in case t is a specialization and we are
1607 emitting an error about incompatible specifications. */
1608 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1610 /* Likewise for the constexpr specifier, in case t is a specialization. */
1611 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1613 /* Pretty print template instantiations only. */
1614 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1615 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1616 && flag_pretty_templates
)
1620 template_args
= DECL_TI_ARGS (t
);
1621 tmpl
= most_general_template (t
);
1622 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1624 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1629 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1630 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1632 fntype
= TREE_TYPE (t
);
1633 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1635 if (DECL_CLASS_SCOPE_P (t
))
1636 cname
= DECL_CONTEXT (t
);
1637 /* This is for partially instantiated template methods. */
1638 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1639 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1641 if (flags
& TFF_DECL_SPECIFIERS
)
1643 if (DECL_STATIC_FUNCTION_P (t
))
1644 pp_cxx_ws_string (pp
, "static");
1645 else if (DECL_VIRTUAL_P (t
))
1646 pp_cxx_ws_string (pp
, "virtual");
1650 if (DECL_DECLARED_CONCEPT_P (t
))
1651 pp_cxx_ws_string (pp
, "concept");
1652 else if (DECL_IMMEDIATE_FUNCTION_P (t
))
1653 pp_cxx_ws_string (pp
, "consteval");
1655 pp_cxx_ws_string (pp
, "constexpr");
1659 /* Print the return type? */
1661 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1662 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1665 ret
= fndecl_declared_return_type (t
);
1666 dump_type_prefix (pp
, ret
, flags
);
1669 /* Print the function name. */
1670 if (!do_outer_scope
)
1674 dump_type (pp
, cname
, flags
);
1675 pp_cxx_colon_colon (pp
);
1678 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1680 dump_function_name (pp
, t
, flags
);
1682 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1684 dump_parameters (pp
, parmtypes
, flags
);
1686 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1688 pp
->padding
= pp_before
;
1689 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1690 dump_ref_qualifier (pp
, fntype
, flags
);
1693 if (tx_safe_fn_type_p (fntype
))
1695 pp
->padding
= pp_before
;
1696 pp_cxx_ws_string (pp
, "transaction_safe");
1699 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1701 pp
->padding
= pp_before
;
1702 dump_exception_spec (pp
, exceptions
, flags
);
1706 dump_type_suffix (pp
, ret
, flags
);
1707 else if (deduction_guide_p (t
))
1709 pp_cxx_ws_string (pp
, "->");
1710 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1714 if (tree ci
= get_constraints (t
))
1715 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1716 pp_cxx_requires_clause (pp
, reqs
);
1718 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1720 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1722 pp_cxx_ws_string (pp
, "[inherited from");
1723 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1724 pp_character (pp
, ']');
1727 else if (template_args
)
1729 bool need_comma
= false;
1731 pp_cxx_begin_template_argument_list (pp
);
1732 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1733 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1735 tree arg
= TREE_VEC_ELT (template_args
, i
);
1737 pp_separate_with_comma (pp
);
1738 if (ARGUMENT_PACK_P (arg
))
1739 pp_cxx_left_brace (pp
);
1740 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1741 if (ARGUMENT_PACK_P (arg
))
1742 pp_cxx_right_brace (pp
);
1745 pp_cxx_end_template_argument_list (pp
);
1749 /* Print a parameter list. If this is for a member function, the
1750 member object ptr (and any other hidden args) should have
1751 already been removed. */
1754 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1757 flags
&= ~TFF_SCOPE
;
1758 pp_cxx_left_paren (pp
);
1760 for (first
= 1; parmtypes
!= void_list_node
;
1761 parmtypes
= TREE_CHAIN (parmtypes
))
1764 pp_separate_with_comma (pp
);
1768 pp_cxx_ws_string (pp
, "...");
1772 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1774 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1776 pp_cxx_whitespace (pp
);
1778 pp_cxx_whitespace (pp
);
1779 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1783 pp_cxx_right_paren (pp
);
1786 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1789 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1791 if (FUNCTION_REF_QUALIFIED (t
))
1793 pp
->padding
= pp_before
;
1794 if (FUNCTION_RVALUE_QUALIFIED (t
))
1795 pp_cxx_ws_string (pp
, "&&");
1797 pp_cxx_ws_string (pp
, "&");
1801 /* Print an exception specification. T is the exception specification. */
1804 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1806 if (t
&& TREE_PURPOSE (t
))
1808 pp_cxx_ws_string (pp
, "noexcept");
1809 if (!integer_onep (TREE_PURPOSE (t
)))
1811 pp_cxx_whitespace (pp
);
1812 pp_cxx_left_paren (pp
);
1813 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1814 pp_cxx_ws_string (pp
, "<uninstantiated>");
1816 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1817 pp_cxx_right_paren (pp
);
1822 pp_cxx_ws_string (pp
, "throw");
1823 pp_cxx_whitespace (pp
);
1824 pp_cxx_left_paren (pp
);
1825 if (TREE_VALUE (t
) != NULL_TREE
)
1828 dump_type (pp
, TREE_VALUE (t
), flags
);
1832 pp_separate_with_comma (pp
);
1834 pp_cxx_right_paren (pp
);
1838 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1839 and destructors properly. */
1842 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1844 tree name
= DECL_NAME (t
);
1846 /* We can get here with a decl that was synthesized by language-
1847 independent machinery (e.g. coverage.c) in which case it won't
1848 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1849 will crash. In this case it is safe just to print out the
1851 if (!DECL_LANG_SPECIFIC (t
))
1853 pp_cxx_tree_identifier (pp
, name
);
1857 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1858 t
= DECL_TEMPLATE_RESULT (t
);
1860 /* Don't let the user see __comp_ctor et al. */
1861 if (DECL_CONSTRUCTOR_P (t
)
1862 || DECL_DESTRUCTOR_P (t
))
1864 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1865 name
= get_identifier ("<lambda>");
1866 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1867 name
= get_identifier ("<constructor>");
1869 name
= constructor_name (DECL_CONTEXT (t
));
1872 if (DECL_DESTRUCTOR_P (t
))
1874 pp_cxx_complement (pp
);
1875 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1877 else if (DECL_CONV_FN_P (t
))
1879 /* This cannot use the hack that the operator's return
1880 type is stashed off of its name because it may be
1881 used for error reporting. In the case of conflicting
1882 declarations, both will have the same name, yet
1883 the types will be different, hence the TREE_TYPE field
1884 of the first name will be clobbered by the second. */
1885 pp_cxx_ws_string (pp
, "operator");
1886 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1889 dump_decl (pp
, name
, flags
);
1891 if (DECL_TEMPLATE_INFO (t
)
1892 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1893 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1894 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1895 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1899 /* Dump the template parameters from the template info INFO under control of
1900 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1901 specialization (partial or complete). For partial specializations we show
1902 the specialized parameter values. For a primary template we show no
1906 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1907 int primary
, int flags
)
1909 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1911 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1913 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1914 pp_cxx_begin_template_argument_list (pp
);
1916 /* Be careful only to print things when we have them, so as not
1917 to crash producing error messages. */
1918 if (args
&& !primary
)
1921 len
= get_non_default_template_args_count (args
, flags
);
1923 args
= INNERMOST_TEMPLATE_ARGS (args
);
1924 for (ix
= 0; ix
!= len
; ix
++)
1926 tree arg
= TREE_VEC_ELT (args
, ix
);
1928 /* Only print a comma if we know there is an argument coming. In
1929 the case of an empty template argument pack, no actual
1930 argument will be printed. */
1932 && (!ARGUMENT_PACK_P (arg
)
1933 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1934 pp_separate_with_comma (pp
);
1937 pp_string (pp
, M_("<template parameter error>"));
1939 dump_template_argument (pp
, arg
, flags
);
1944 tree tpl
= TI_TEMPLATE (info
);
1945 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1948 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1949 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1951 for (ix
= 0; ix
!= len
; ix
++)
1955 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1957 pp_string (pp
, M_("<template parameter error>"));
1961 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1964 pp_separate_with_comma (pp
);
1966 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1969 pp_cxx_end_template_argument_list (pp
);
1972 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1973 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1976 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1979 call_expr_arg_iterator iter
;
1981 pp_cxx_left_paren (pp
);
1982 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1988 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1989 if (more_call_expr_args_p (&iter
))
1990 pp_separate_with_comma (pp
);
1993 pp_cxx_right_paren (pp
);
1996 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1997 using flags FLAGS. Skip over the first argument if SKIPFIRST is
2001 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2005 aggr_init_expr_arg_iterator iter
;
2007 pp_cxx_left_paren (pp
);
2008 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2014 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2015 if (more_aggr_init_expr_args_p (&iter
))
2016 pp_separate_with_comma (pp
);
2019 pp_cxx_right_paren (pp
);
2022 /* Print out a list of initializers (subr of dump_expr). */
2025 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2029 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2032 pp_separate_with_comma (pp
);
2036 /* Print out a vector of initializers (subr of dump_expr). */
2039 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2042 unsigned HOST_WIDE_INT idx
;
2045 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2047 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2048 if (idx
!= v
->length () - 1)
2049 pp_separate_with_comma (pp
);
2054 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2055 function. Resolve it to a close relative -- in the sense of static
2056 type -- variant being overridden. That is close to what was written in
2057 the source code. Subroutine of dump_expr. */
2060 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2062 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2063 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2064 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2067 fun
= TREE_CHAIN (fun
);
2068 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2069 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2075 /* Print out an expression E under control of FLAGS. */
2078 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2085 if (STATEMENT_CLASS_P (t
))
2087 pp_cxx_ws_string (pp
, M_("<statement>"));
2091 switch (TREE_CODE (t
))
2099 case NAMESPACE_DECL
:
2104 case IDENTIFIER_NODE
:
2105 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2106 |TFF_TEMPLATE_HEADER
))
2107 | TFF_NO_TEMPLATE_BINDINGS
2108 | TFF_NO_FUNCTION_ARGUMENTS
));
2112 if (SSA_NAME_VAR (t
)
2113 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2114 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2116 pp_cxx_ws_string (pp
, M_("<unknown>"));
2127 case USERDEF_LITERAL
:
2128 pp_cxx_userdef_literal (pp
, t
);
2132 /* While waiting for caret diagnostics, avoid printing
2133 __cxa_allocate_exception, __cxa_throw, and the like. */
2134 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2139 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2140 pp_cxx_colon_colon (pp
);
2141 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2145 pp_cxx_left_paren (pp
);
2146 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2147 pp_separate_with_comma (pp
);
2148 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2149 pp_cxx_right_paren (pp
);
2154 pp_cxx_left_paren (pp
);
2155 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2156 pp_string (pp
, " ? ");
2157 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2158 pp_string (pp
, " : ");
2159 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2160 pp_cxx_right_paren (pp
);
2164 if (TREE_HAS_CONSTRUCTOR (t
))
2166 pp_cxx_ws_string (pp
, "new");
2167 pp_cxx_whitespace (pp
);
2168 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2171 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2174 case AGGR_INIT_EXPR
:
2176 tree fn
= NULL_TREE
;
2178 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2179 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2181 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2183 if (DECL_CONSTRUCTOR_P (fn
))
2184 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2186 dump_decl (pp
, fn
, 0);
2189 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2191 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2196 tree fn
= CALL_EXPR_FN (t
);
2197 bool skipfirst
= false;
2199 /* Deal with internal functions. */
2200 if (fn
== NULL_TREE
)
2202 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2203 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2207 if (TREE_CODE (fn
) == ADDR_EXPR
)
2208 fn
= TREE_OPERAND (fn
, 0);
2210 /* Nobody is interested in seeing the guts of vcalls. */
2211 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2212 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2214 if (TREE_TYPE (fn
) != NULL_TREE
2215 && NEXT_CODE (fn
) == METHOD_TYPE
2216 && call_expr_nargs (t
))
2218 tree ob
= CALL_EXPR_ARG (t
, 0);
2219 if (TREE_CODE (ob
) == ADDR_EXPR
)
2221 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2222 flags
| TFF_EXPR_IN_PARENS
);
2225 else if (!is_this_parameter (ob
))
2227 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2232 if (flag_sanitize
& SANITIZE_UNDEFINED
2233 && is_ubsan_builtin_p (fn
))
2235 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2238 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2239 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2244 /* Note that this only works for G++ target exprs. If somebody
2245 builds a general TARGET_EXPR, there's no way to represent that
2246 it initializes anything other that the parameter slot for the
2247 default argument. Note we may have cleared out the first
2248 operand in expand_expr, so don't go killing ourselves. */
2249 if (TREE_OPERAND (t
, 1))
2250 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2253 case POINTER_PLUS_EXPR
:
2254 dump_binary_op (pp
, "+", t
, flags
);
2257 case POINTER_DIFF_EXPR
:
2258 dump_binary_op (pp
, "-", t
, flags
);
2263 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2269 case TRUNC_DIV_EXPR
:
2270 case TRUNC_MOD_EXPR
:
2278 case TRUTH_ANDIF_EXPR
:
2279 case TRUTH_ORIF_EXPR
:
2286 case SPACESHIP_EXPR
:
2287 case EXACT_DIV_EXPR
:
2288 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2292 case FLOOR_DIV_EXPR
:
2293 case ROUND_DIV_EXPR
:
2295 dump_binary_op (pp
, "/", t
, flags
);
2299 case FLOOR_MOD_EXPR
:
2300 case ROUND_MOD_EXPR
:
2301 dump_binary_op (pp
, "%", t
, flags
);
2306 tree ob
= TREE_OPERAND (t
, 0);
2307 if (INDIRECT_REF_P (ob
))
2309 ob
= TREE_OPERAND (ob
, 0);
2310 if (!is_this_parameter (ob
))
2312 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2313 if (TYPE_REF_P (TREE_TYPE (ob
)))
2321 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2322 if (TREE_CODE (ob
) != ARROW_EXPR
)
2325 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2330 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2331 pp_cxx_left_bracket (pp
);
2332 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2333 pp_cxx_right_bracket (pp
);
2336 case UNARY_PLUS_EXPR
:
2337 dump_unary_op (pp
, "+", t
, flags
);
2341 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2342 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2343 /* An ADDR_EXPR can have reference type. In that case, we
2344 shouldn't print the `&' doing so indicates to the user
2345 that the expression has pointer type. */
2347 && TYPE_REF_P (TREE_TYPE (t
))))
2348 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2349 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2350 dump_unary_op (pp
, "&&", t
, flags
);
2352 dump_unary_op (pp
, "&", t
, flags
);
2356 if (TREE_HAS_CONSTRUCTOR (t
))
2358 t
= TREE_OPERAND (t
, 0);
2359 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2360 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2361 dump_call_expr_args (pp
, t
, flags
, true);
2365 if (TREE_OPERAND (t
,0) != NULL_TREE
2366 && TREE_TYPE (TREE_OPERAND (t
, 0))
2367 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2368 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2370 dump_unary_op (pp
, "*", t
, flags
);
2375 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2376 && integer_zerop (TREE_OPERAND (t
, 1)))
2377 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2381 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2383 pp_cxx_left_paren (pp
);
2384 if (!integer_onep (TYPE_SIZE_UNIT
2385 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2387 pp_cxx_left_paren (pp
);
2388 dump_type (pp
, ptr_type_node
, flags
);
2389 pp_cxx_right_paren (pp
);
2392 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2393 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2395 pp_cxx_ws_string (pp
, "+");
2396 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2398 pp_cxx_right_paren (pp
);
2403 case TARGET_MEM_REF
:
2404 /* TARGET_MEM_REF can't appear directly from source, but can appear
2405 during late GIMPLE optimizations and through late diagnostic we might
2406 need to support it. Print it as dereferencing of a pointer after
2407 cast to the TARGET_MEM_REF type, with pointer arithmetics on some
2408 pointer to single byte types, so
2409 *(type *)((char *) ptr + step * index + index2) if all the operands
2410 are present and the casts are needed. */
2412 pp_cxx_left_paren (pp
);
2413 if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))) == NULL_TREE
2414 || !integer_onep (TYPE_SIZE_UNIT
2415 (TREE_TYPE (TREE_TYPE (TMR_BASE (t
))))))
2417 if (TYPE_SIZE_UNIT (TREE_TYPE (t
))
2418 && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t
))))
2420 pp_cxx_left_paren (pp
);
2421 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2425 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2426 pp_cxx_right_paren (pp
);
2427 pp_cxx_left_paren (pp
);
2428 pp_cxx_left_paren (pp
);
2429 dump_type (pp
, build_pointer_type (char_type_node
), flags
);
2431 pp_cxx_right_paren (pp
);
2433 else if (!same_type_p (TREE_TYPE (t
),
2434 TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))))
2436 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2437 pp_cxx_right_paren (pp
);
2438 pp_cxx_left_paren (pp
);
2440 dump_expr (pp
, TMR_BASE (t
), flags
);
2441 if (TMR_STEP (t
) && TMR_INDEX (t
))
2443 pp_cxx_ws_string (pp
, "+");
2444 dump_expr (pp
, TMR_INDEX (t
), flags
);
2445 pp_cxx_ws_string (pp
, "*");
2446 dump_expr (pp
, TMR_STEP (t
), flags
);
2450 pp_cxx_ws_string (pp
, "+");
2451 dump_expr (pp
, TMR_INDEX2 (t
), flags
);
2453 if (!integer_zerop (TMR_OFFSET (t
)))
2455 pp_cxx_ws_string (pp
, "+");
2456 dump_expr (pp
, fold_convert (ssizetype
, TMR_OFFSET (t
)), flags
);
2458 pp_cxx_right_paren (pp
);
2463 case TRUTH_NOT_EXPR
:
2464 case PREDECREMENT_EXPR
:
2465 case PREINCREMENT_EXPR
:
2466 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2469 case POSTDECREMENT_EXPR
:
2470 case POSTINCREMENT_EXPR
:
2471 pp_cxx_left_paren (pp
);
2472 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2473 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2474 pp_cxx_right_paren (pp
);
2477 case NON_LVALUE_EXPR
:
2478 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2479 should be another level of INDIRECT_REF so that I don't have to do
2481 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2483 tree next
= TREE_TYPE (TREE_TYPE (t
));
2485 while (TYPE_PTR_P (next
))
2486 next
= TREE_TYPE (next
);
2488 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2490 if (flags
& TFF_EXPR_IN_PARENS
)
2491 pp_cxx_left_paren (pp
);
2493 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2494 if (flags
& TFF_EXPR_IN_PARENS
)
2495 pp_cxx_right_paren (pp
);
2498 /* Else fall through. */
2500 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2504 case IMPLICIT_CONV_EXPR
:
2505 case VIEW_CONVERT_EXPR
:
2507 tree op
= TREE_OPERAND (t
, 0);
2508 tree ttype
= TREE_TYPE (t
);
2509 tree optype
= TREE_TYPE (op
);
2511 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2512 && INDIRECT_TYPE_P (ttype
)
2513 && INDIRECT_TYPE_P (optype
)
2514 && same_type_p (TREE_TYPE (optype
),
2517 if (TYPE_REF_P (ttype
))
2520 if (TREE_CODE (op
) == ADDR_EXPR
)
2521 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2523 dump_unary_op (pp
, "*", t
, flags
);
2526 dump_unary_op (pp
, "&", t
, flags
);
2528 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2530 /* It is a cast, but we cannot tell whether it is a
2531 reinterpret or static cast. Use the C style notation. */
2532 if (flags
& TFF_EXPR_IN_PARENS
)
2533 pp_cxx_left_paren (pp
);
2534 pp_cxx_left_paren (pp
);
2535 dump_type (pp
, TREE_TYPE (t
), flags
);
2536 pp_cxx_right_paren (pp
);
2537 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2538 if (flags
& TFF_EXPR_IN_PARENS
)
2539 pp_cxx_right_paren (pp
);
2542 dump_expr (pp
, op
, flags
);
2547 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2549 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2551 if (integer_zerop (idx
))
2553 /* A NULL pointer-to-member constant. */
2554 pp_cxx_left_paren (pp
);
2555 pp_cxx_left_paren (pp
);
2556 dump_type (pp
, TREE_TYPE (t
), flags
);
2557 pp_cxx_right_paren (pp
);
2558 pp_character (pp
, '0');
2559 pp_cxx_right_paren (pp
);
2562 else if (tree_fits_shwi_p (idx
))
2565 unsigned HOST_WIDE_INT n
;
2567 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2568 t
= TYPE_METHOD_BASETYPE (t
);
2569 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2571 n
= tree_to_shwi (idx
);
2573 /* Map vtable index back one, to allow for the null pointer to
2577 while (n
> 0 && virtuals
)
2580 virtuals
= TREE_CHAIN (virtuals
);
2584 dump_expr (pp
, BV_FN (virtuals
),
2585 flags
| TFF_EXPR_IN_PARENS
);
2590 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2591 pp_string (pp
, "<lambda closure object>");
2592 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2594 dump_type (pp
, TREE_TYPE (t
), 0);
2595 pp_cxx_left_paren (pp
);
2596 pp_cxx_right_paren (pp
);
2600 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2601 dump_type (pp
, TREE_TYPE (t
), 0);
2602 pp_cxx_left_brace (pp
);
2603 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2604 pp_cxx_right_brace (pp
);
2611 tree ob
= TREE_OPERAND (t
, 0);
2612 if (is_dummy_object (ob
))
2614 t
= TREE_OPERAND (t
, 1);
2615 if (TREE_CODE (t
) == FUNCTION_DECL
)
2617 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2618 else if (BASELINK_P (t
))
2619 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2620 flags
| TFF_EXPR_IN_PARENS
);
2622 dump_decl (pp
, t
, flags
);
2626 if (INDIRECT_REF_P (ob
))
2628 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2634 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2638 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2643 case TEMPLATE_PARM_INDEX
:
2644 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2648 if (TREE_OPERAND (t
, 0) == NULL_TREE
2649 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2651 dump_type (pp
, TREE_TYPE (t
), flags
);
2652 pp_cxx_left_paren (pp
);
2653 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2654 pp_cxx_right_paren (pp
);
2658 pp_cxx_left_paren (pp
);
2659 dump_type (pp
, TREE_TYPE (t
), flags
);
2660 pp_cxx_right_paren (pp
);
2661 pp_cxx_left_paren (pp
);
2662 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2663 pp_cxx_right_paren (pp
);
2667 case STATIC_CAST_EXPR
:
2668 pp_cxx_ws_string (pp
, "static_cast");
2670 case REINTERPRET_CAST_EXPR
:
2671 pp_cxx_ws_string (pp
, "reinterpret_cast");
2673 case CONST_CAST_EXPR
:
2674 pp_cxx_ws_string (pp
, "const_cast");
2676 case DYNAMIC_CAST_EXPR
:
2677 pp_cxx_ws_string (pp
, "dynamic_cast");
2679 pp_cxx_begin_template_argument_list (pp
);
2680 dump_type (pp
, TREE_TYPE (t
), flags
);
2681 pp_cxx_end_template_argument_list (pp
);
2682 pp_cxx_left_paren (pp
);
2683 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2684 pp_cxx_right_paren (pp
);
2688 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2694 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2695 pp_cxx_ws_string (pp
, "sizeof");
2698 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2699 pp_cxx_ws_string (pp
, "__alignof__");
2701 op
= TREE_OPERAND (t
, 0);
2702 if (PACK_EXPANSION_P (op
))
2704 pp_string (pp
, "...");
2705 op
= PACK_EXPANSION_PATTERN (op
);
2707 pp_cxx_whitespace (pp
);
2708 pp_cxx_left_paren (pp
);
2709 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2710 dump_type (pp
, TREE_TYPE (op
), flags
);
2711 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2712 dump_type (pp
, op
, flags
);
2714 dump_expr (pp
, op
, flags
);
2715 pp_cxx_right_paren (pp
);
2718 case AT_ENCODE_EXPR
:
2719 pp_cxx_ws_string (pp
, "@encode");
2720 pp_cxx_whitespace (pp
);
2721 pp_cxx_left_paren (pp
);
2722 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2723 pp_cxx_right_paren (pp
);
2727 pp_cxx_ws_string (pp
, "noexcept");
2728 pp_cxx_whitespace (pp
);
2729 pp_cxx_left_paren (pp
);
2730 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2731 pp_cxx_right_paren (pp
);
2736 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2737 pp_cxx_whitespace (pp
);
2738 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2741 case DEFERRED_PARSE
:
2742 pp_string (pp
, M_("<unparsed>"));
2745 case TRY_CATCH_EXPR
:
2746 case CLEANUP_POINT_EXPR
:
2747 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2750 case PSEUDO_DTOR_EXPR
:
2751 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2753 if (TREE_OPERAND (t
, 1))
2755 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2756 pp_cxx_colon_colon (pp
);
2758 pp_cxx_complement (pp
);
2759 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2762 case TEMPLATE_ID_EXPR
:
2763 dump_decl (pp
, t
, flags
);
2769 case STATEMENT_LIST
:
2770 /* We don't yet have a way of dumping statements in a
2771 human-readable format. */
2772 pp_string (pp
, "({...})");
2776 pp_string (pp
, "while (1) { ");
2777 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2778 pp_cxx_right_brace (pp
);
2782 pp_string (pp
, "if (");
2783 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2784 pp_string (pp
, ") break; ");
2788 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2791 case EMPTY_CLASS_EXPR
:
2792 dump_type (pp
, TREE_TYPE (t
), flags
);
2793 pp_cxx_left_paren (pp
);
2794 pp_cxx_right_paren (pp
);
2797 case NON_DEPENDENT_EXPR
:
2798 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2801 case ARGUMENT_PACK_SELECT
:
2802 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2815 pp_type_specifier_seq (pp
, t
);
2819 /* We get here when we want to print a dependent type as an
2820 id-expression, without any disambiguator decoration. */
2821 pp
->id_expression (t
);
2824 case TEMPLATE_TYPE_PARM
:
2825 case TEMPLATE_TEMPLATE_PARM
:
2826 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2827 dump_type (pp
, t
, flags
);
2831 pp_cxx_trait_expression (pp
, t
);
2835 pp_cxx_va_arg_expression (pp
, t
);
2839 pp_cxx_offsetof_expression (pp
, t
);
2842 case ADDRESSOF_EXPR
:
2843 pp_cxx_addressof_expression (pp
, t
);
2847 dump_decl (pp
, t
, flags
);
2850 case EXPR_PACK_EXPANSION
:
2851 case UNARY_LEFT_FOLD_EXPR
:
2852 case UNARY_RIGHT_FOLD_EXPR
:
2853 case BINARY_LEFT_FOLD_EXPR
:
2854 case BINARY_RIGHT_FOLD_EXPR
:
2861 case VEC_DELETE_EXPR
:
2868 case UNORDERED_EXPR
:
2878 case FIX_TRUNC_EXPR
:
2883 case TRUTH_AND_EXPR
:
2885 case TRUTH_XOR_EXPR
:
2886 if (flags
& TFF_EXPR_IN_PARENS
)
2887 pp_cxx_left_paren (pp
);
2889 if (flags
& TFF_EXPR_IN_PARENS
)
2890 pp_cxx_right_paren (pp
);
2894 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2898 pp_string (pp
, M_("<lambda>"));
2902 pp_cxx_left_paren (pp
);
2903 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2904 pp_cxx_right_paren (pp
);
2908 pp_cxx_requires_expr (cxx_pp
, t
);
2912 pp_cxx_simple_requirement (cxx_pp
, t
);
2916 pp_cxx_type_requirement (cxx_pp
, t
);
2920 pp_cxx_compound_requirement (cxx_pp
, t
);
2924 pp_cxx_nested_requirement (cxx_pp
, t
);
2932 pp_cxx_constraint (cxx_pp
, t
);
2936 case PLACEHOLDER_EXPR
:
2937 pp_string (pp
, M_("*this"));
2941 dump_expr_list (pp
, t
, flags
);
2944 /* This list is incomplete, but should suffice for now.
2945 It is very important that `sorry' does not call
2946 `report_error_function'. That could cause an infinite loop. */
2948 pp_unsupported_tree (pp
, t
);
2951 pp_string (pp
, M_("<expression error>"));
2957 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2960 pp_cxx_left_paren (pp
);
2961 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2962 pp_cxx_whitespace (pp
);
2964 pp_cxx_ws_string (pp
, opstring
);
2966 pp_string (pp
, M_("<unknown operator>"));
2967 pp_cxx_whitespace (pp
);
2968 tree op1
= TREE_OPERAND (t
, 1);
2969 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
2970 && TREE_CODE (op1
) == INTEGER_CST
2971 && tree_int_cst_sign_bit (op1
))
2972 /* A pointer minus an integer is represented internally as plus a very
2973 large number, don't expose that to users. */
2974 op1
= convert (ssizetype
, op1
);
2975 dump_expr (pp
, op1
, flags
| TFF_EXPR_IN_PARENS
);
2976 pp_cxx_right_paren (pp
);
2980 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2982 if (flags
& TFF_EXPR_IN_PARENS
)
2983 pp_cxx_left_paren (pp
);
2984 pp_cxx_ws_string (pp
, opstring
);
2985 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2986 if (flags
& TFF_EXPR_IN_PARENS
)
2987 pp_cxx_right_paren (pp
);
2991 reinit_cxx_pp (void)
2993 pp_clear_output_area (cxx_pp
);
2994 cxx_pp
->padding
= pp_none
;
2995 pp_indentation (cxx_pp
) = 0;
2996 pp_needs_newline (cxx_pp
) = false;
2997 cxx_pp
->enclosing_scope
= current_function_decl
;
3000 /* Same as pp_formatted_text, except the return string is a separate
3001 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3004 pp_ggc_formatted_text (pretty_printer
*pp
)
3006 return ggc_strdup (pp_formatted_text (pp
));
3009 /* Exported interface to stringifying types, exprs and decls under TFF_*
3013 type_as_string (tree typ
, int flags
)
3016 pp_translate_identifiers (cxx_pp
) = false;
3017 dump_type (cxx_pp
, typ
, flags
);
3018 return pp_ggc_formatted_text (cxx_pp
);
3022 type_as_string_translate (tree typ
, int flags
)
3025 dump_type (cxx_pp
, typ
, flags
);
3026 return pp_ggc_formatted_text (cxx_pp
);
3030 expr_as_string (tree decl
, int flags
)
3033 pp_translate_identifiers (cxx_pp
) = false;
3034 dump_expr (cxx_pp
, decl
, flags
);
3035 return pp_ggc_formatted_text (cxx_pp
);
3038 /* Wrap decl_as_string with options appropriate for dwarf. */
3041 decl_as_dwarf_string (tree decl
, int flags
)
3044 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3045 here will be adequate to get the desired behavior. */
3046 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3047 name
= decl_as_string (decl
, flags
);
3048 /* Subsequent calls to the pretty printer shouldn't use this style. */
3049 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3054 decl_as_string (tree decl
, int flags
)
3057 pp_translate_identifiers (cxx_pp
) = false;
3058 dump_decl (cxx_pp
, decl
, flags
);
3059 return pp_ggc_formatted_text (cxx_pp
);
3063 decl_as_string_translate (tree decl
, int flags
)
3066 dump_decl (cxx_pp
, decl
, flags
);
3067 return pp_ggc_formatted_text (cxx_pp
);
3070 /* Wrap lang_decl_name with options appropriate for dwarf. */
3073 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3076 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3077 here will be adequate to get the desired behavior. */
3078 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3079 name
= lang_decl_name (decl
, v
, translate
);
3080 /* Subsequent calls to the pretty printer shouldn't use this style. */
3081 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3085 /* Generate the three forms of printable names for cxx_printable_name. */
3088 lang_decl_name (tree decl
, int v
, bool translate
)
3092 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3093 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3096 pp_translate_identifiers (cxx_pp
) = translate
;
3098 && (DECL_CLASS_SCOPE_P (decl
)
3099 || (DECL_NAMESPACE_SCOPE_P (decl
)
3100 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3102 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3103 pp_cxx_colon_colon (cxx_pp
);
3106 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3107 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3108 else if ((DECL_NAME (decl
) == NULL_TREE
)
3109 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3110 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3112 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3114 return pp_ggc_formatted_text (cxx_pp
);
3117 /* Return the location of a tree passed to %+ formats. */
3120 location_of (tree t
)
3124 t
= TYPE_MAIN_DECL (t
);
3126 return input_location
;
3128 else if (TREE_CODE (t
) == OVERLOAD
)
3132 return DECL_SOURCE_LOCATION (t
);
3133 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3134 return defparse_location (t
);
3135 return cp_expr_loc_or_input_loc (t
);
3138 /* Now the interfaces from error et al to dump_type et al. Each takes an
3139 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3143 decl_to_string (tree decl
, int verbose
)
3147 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3148 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3149 flags
= TFF_CLASS_KEY_OR_ENUM
;
3151 flags
|= TFF_DECL_SPECIFIERS
;
3152 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3153 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3154 flags
|= TFF_TEMPLATE_HEADER
;
3157 dump_decl (cxx_pp
, decl
, flags
);
3158 return pp_ggc_formatted_text (cxx_pp
);
3162 expr_to_string (tree decl
)
3165 dump_expr (cxx_pp
, decl
, 0);
3166 return pp_ggc_formatted_text (cxx_pp
);
3170 fndecl_to_string (tree fndecl
, int verbose
)
3174 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3175 | TFF_TEMPLATE_HEADER
;
3177 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3179 dump_decl (cxx_pp
, fndecl
, flags
);
3180 return pp_ggc_formatted_text (cxx_pp
);
3185 code_to_string (enum tree_code c
)
3187 return get_tree_code_name (c
);
3191 language_to_string (enum languages c
)
3198 case lang_cplusplus
:
3207 /* Return the proper printed version of a parameter to a C++ function. */
3210 parm_to_string (int p
)
3214 pp_string (cxx_pp
, "'this'");
3216 pp_decimal_int (cxx_pp
, p
+ 1);
3217 return pp_ggc_formatted_text (cxx_pp
);
3221 op_to_string (bool assop
, enum tree_code p
)
3223 tree id
= ovl_op_identifier (assop
, p
);
3224 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3227 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3229 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3230 string in appropriate places, and *QUOTE is written to with false
3231 to suppress pp_format's trailing close quote so that e.g.
3232 foo_typedef {aka underlying_foo} {enum}
3233 can be printed by "%qT" as:
3234 `foo_typedef' {aka `underlying_foo'} {enum}
3236 `foo_typedef {aka underlying_foo} {enum}'
3237 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3238 then a leading open quote will be added, whereas if POSTPROCESSED is false
3239 (for handling %T) then any leading quote has already been added by
3240 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3243 SHOW_COLOR is used to determine the colorization of any quotes that
3247 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3252 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3253 flags
|= TFF_TEMPLATE_HEADER
;
3257 if (postprocessed
&& quote
&& *quote
)
3258 pp_begin_quote (cxx_pp
, show_color
);
3260 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3261 int type_start
, type_len
;
3262 type_start
= obstack_object_size (ob
);
3264 dump_type (cxx_pp
, typ
, flags
);
3266 /* Remember the end of the initial dump. */
3267 type_len
= obstack_object_size (ob
) - type_start
;
3269 /* If we're printing a type that involves typedefs, also print the
3270 stripped version. But sometimes the stripped version looks
3271 exactly the same, so we don't want it after all. To avoid printing
3272 it in that case, we play ugly obstack games. */
3273 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3274 && !uses_template_parms (typ
))
3276 int aka_start
, aka_len
; char *p
;
3277 tree aka
= strip_typedefs (typ
, NULL
, STF_USER_VISIBLE
);
3278 if (quote
&& *quote
)
3279 pp_end_quote (cxx_pp
, show_color
);
3280 pp_string (cxx_pp
, " {aka");
3281 pp_cxx_whitespace (cxx_pp
);
3282 if (quote
&& *quote
)
3283 pp_begin_quote (cxx_pp
, show_color
);
3284 /* And remember the start of the aka dump. */
3285 aka_start
= obstack_object_size (ob
);
3286 dump_type (cxx_pp
, aka
, flags
);
3287 aka_len
= obstack_object_size (ob
) - aka_start
;
3288 if (quote
&& *quote
)
3289 pp_end_quote (cxx_pp
, show_color
);
3290 pp_right_brace (cxx_pp
);
3291 p
= (char*)obstack_base (ob
);
3292 /* If they are identical, cut off the aka by unwinding the obstack. */
3293 if (type_len
== aka_len
3294 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3296 /* We can't add a '\0' here, since we may be adding a closing quote
3297 below, and it would be hidden by the '\0'.
3298 Instead, manually unwind the current object within the obstack
3299 so that the insertion point is at the end of the type, before
3301 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3302 gcc_assert (delta
<= 0);
3303 obstack_blank_fast (ob
, delta
);
3307 /* No further closing quotes are needed. */
3311 if (quote
&& *quote
)
3313 pp_end_quote (cxx_pp
, show_color
);
3316 return pp_ggc_formatted_text (cxx_pp
);
3320 args_to_string (tree p
, int verbose
)
3324 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3329 if (TYPE_P (TREE_VALUE (p
)))
3330 return type_as_string_translate (p
, flags
);
3333 for (; p
; p
= TREE_CHAIN (p
))
3335 if (null_node_p (TREE_VALUE (p
)))
3336 pp_cxx_ws_string (cxx_pp
, "NULL");
3338 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3340 pp_separate_with_comma (cxx_pp
);
3342 return pp_ggc_formatted_text (cxx_pp
);
3345 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3346 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3350 subst_to_string (tree p
)
3352 tree decl
= TREE_PURPOSE (p
);
3353 tree targs
= TREE_VALUE (p
);
3354 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3355 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3356 |TFF_NO_TEMPLATE_BINDINGS
);
3362 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3363 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3364 return pp_ggc_formatted_text (cxx_pp
);
3368 cv_to_string (tree p
, int v
)
3371 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3372 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3373 return pp_ggc_formatted_text (cxx_pp
);
3377 eh_spec_to_string (tree p
, int /*v*/)
3381 dump_exception_spec (cxx_pp
, p
, flags
);
3382 return pp_ggc_formatted_text (cxx_pp
);
3385 /* Langhook for print_error_function. */
3387 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3388 diagnostic_info
*diagnostic
)
3392 prefix
= xstrdup (file
);
3395 lhd_print_error_function (context
, file
, diagnostic
);
3396 pp_set_prefix (context
->printer
, prefix
);
3397 maybe_print_instantiation_context (context
);
3401 cp_diagnostic_starter (diagnostic_context
*context
,
3402 diagnostic_info
*diagnostic
)
3404 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3405 cp_print_error_function (context
, diagnostic
);
3406 maybe_print_instantiation_context (context
);
3407 maybe_print_constexpr_context (context
);
3408 maybe_print_constraint_context (context
);
3409 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3413 /* Print current function onto BUFFER, in the process of reporting
3414 a diagnostic message. Called from cp_diagnostic_starter. */
3416 cp_print_error_function (diagnostic_context
*context
,
3417 diagnostic_info
*diagnostic
)
3419 /* If we are in an instantiation context, current_function_decl is likely
3420 to be wrong, so just rely on print_instantiation_full_context. */
3421 if (current_instantiation ())
3423 /* The above is true for constraint satisfaction also. */
3424 if (current_failed_constraint
)
3426 if (diagnostic_last_function_changed (context
, diagnostic
))
3428 char *old_prefix
= pp_take_prefix (context
->printer
);
3429 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3430 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3431 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3432 ? file_name_as_prefix (context
, file
) : NULL
;
3434 pp_set_prefix (context
->printer
, new_prefix
);
3436 if (current_function_decl
== NULL
)
3437 pp_string (context
->printer
, _("At global scope:"));
3442 if (abstract_origin
)
3444 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3445 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3449 fndecl
= current_function_decl
;
3451 pp_printf (context
->printer
, function_category (fndecl
),
3452 cxx_printable_name_translate (fndecl
, 2));
3454 while (abstract_origin
)
3457 tree block
= abstract_origin
;
3459 locus
= &BLOCK_SOURCE_LOCATION (block
);
3461 block
= BLOCK_SUPERCONTEXT (block
);
3462 while (block
&& TREE_CODE (block
) == BLOCK
3463 && BLOCK_ABSTRACT_ORIGIN (block
))
3465 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3466 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3471 else if (TREE_CODE (ao
) != BLOCK
)
3474 block
= BLOCK_SUPERCONTEXT (block
);
3477 abstract_origin
= block
;
3480 while (block
&& TREE_CODE (block
) == BLOCK
)
3481 block
= BLOCK_SUPERCONTEXT (block
);
3483 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3485 abstract_origin
= NULL
;
3489 expanded_location s
= expand_location (*locus
);
3490 pp_character (context
->printer
, ',');
3491 pp_newline (context
->printer
);
3494 if (context
->show_column
&& s
.column
!= 0)
3495 pp_printf (context
->printer
,
3496 _(" inlined from %qs at %r%s:%d:%d%R"),
3497 cxx_printable_name_translate (fndecl
, 2),
3498 "locus", s
.file
, s
.line
, s
.column
);
3500 pp_printf (context
->printer
,
3501 _(" inlined from %qs at %r%s:%d%R"),
3502 cxx_printable_name_translate (fndecl
, 2),
3503 "locus", s
.file
, s
.line
);
3507 pp_printf (context
->printer
, _(" inlined from %qs"),
3508 cxx_printable_name_translate (fndecl
, 2));
3511 pp_character (context
->printer
, ':');
3513 pp_newline (context
->printer
);
3515 diagnostic_set_last_function (context
, diagnostic
);
3516 pp_destroy_prefix (context
->printer
);
3517 context
->printer
->prefix
= old_prefix
;
3521 /* Returns a description of FUNCTION using standard terminology. The
3522 result is a format string of the form "In CATEGORY %qs". */
3524 function_category (tree fn
)
3526 /* We can get called from the middle-end for diagnostics of function
3527 clones. Make sure we have language specific information before
3528 dereferencing it. */
3529 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3530 && DECL_FUNCTION_MEMBER_P (fn
))
3532 if (DECL_STATIC_FUNCTION_P (fn
))
3533 return _("In static member function %qs");
3534 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3535 return _("In copy constructor %qs");
3536 else if (DECL_CONSTRUCTOR_P (fn
))
3537 return _("In constructor %qs");
3538 else if (DECL_DESTRUCTOR_P (fn
))
3539 return _("In destructor %qs");
3540 else if (LAMBDA_FUNCTION_P (fn
))
3541 return _("In lambda function");
3543 return _("In member function %qs");
3546 return _("In function %qs");
3549 /* Report the full context of a current template instantiation,
3552 print_instantiation_full_context (diagnostic_context
*context
)
3554 struct tinst_level
*p
= current_instantiation ();
3555 location_t location
= input_location
;
3559 pp_verbatim (context
->printer
,
3561 ? _("%s: In substitution of %qS:\n")
3562 : _("%s: In instantiation of %q#D:\n"),
3563 LOCATION_FILE (location
),
3566 location
= p
->locus
;
3570 print_instantiation_partial_context (context
, p
, location
);
3573 /* Helper function of print_instantiation_partial_context() that
3574 prints a single line of instantiation context. */
3577 print_instantiation_partial_context_line (diagnostic_context
*context
,
3578 struct tinst_level
*t
,
3579 location_t loc
, bool recursive_p
)
3581 if (loc
== UNKNOWN_LOCATION
)
3584 expanded_location xloc
= expand_location (loc
);
3586 if (context
->show_column
)
3587 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3588 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3590 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3591 "locus", xloc
.file
, xloc
.line
);
3596 pp_verbatim (context
->printer
,
3598 ? _("recursively required by substitution of %qS\n")
3599 : _("required by substitution of %qS\n"),
3602 pp_verbatim (context
->printer
,
3604 ? _("recursively required from %q#D\n")
3605 : _("required from %q#D\n"),
3610 pp_verbatim (context
->printer
,
3612 ? _("recursively required from here\n")
3613 : _("required from here\n"));
3617 /* Same as print_instantiation_full_context but less verbose. */
3620 print_instantiation_partial_context (diagnostic_context
*context
,
3621 struct tinst_level
*t0
, location_t loc
)
3623 struct tinst_level
*t
;
3626 location_t prev_loc
= loc
;
3628 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3629 if (prev_loc
!= t
->locus
)
3631 prev_loc
= t
->locus
;
3637 if (template_backtrace_limit
3638 && n_total
> template_backtrace_limit
)
3640 int skip
= n_total
- template_backtrace_limit
;
3641 int head
= template_backtrace_limit
/ 2;
3643 /* Avoid skipping just 1. If so, skip 2. */
3647 head
= (template_backtrace_limit
- 1) / 2;
3650 for (n
= 0; n
< head
; n
++)
3652 gcc_assert (t
!= NULL
);
3653 if (loc
!= t
->locus
)
3654 print_instantiation_partial_context_line (context
, t
, loc
,
3655 /*recursive_p=*/false);
3659 if (t
!= NULL
&& skip
> 0)
3661 expanded_location xloc
;
3662 xloc
= expand_location (loc
);
3663 if (context
->show_column
)
3664 pp_verbatim (context
->printer
,
3665 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3666 "contexts, use -ftemplate-backtrace-limit=0 to "
3668 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3670 pp_verbatim (context
->printer
,
3671 _("%r%s:%d:%R [ skipping %d instantiation "
3672 "contexts, use -ftemplate-backtrace-limit=0 to "
3674 "locus", xloc
.file
, xloc
.line
, skip
);
3679 } while (t
!= NULL
&& --skip
> 0);
3685 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3690 print_instantiation_partial_context_line (context
, t
, loc
,
3695 print_instantiation_partial_context_line (context
, NULL
, loc
,
3696 /*recursive_p=*/false);
3699 /* Called from cp_thing to print the template context for an error. */
3701 maybe_print_instantiation_context (diagnostic_context
*context
)
3703 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3706 record_last_problematic_instantiation ();
3707 print_instantiation_full_context (context
);
3710 /* Report what constexpr call(s) we're trying to expand, if any. */
3713 maybe_print_constexpr_context (diagnostic_context
*context
)
3715 vec
<tree
> call_stack
= cx_error_context ();
3719 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3721 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3722 const char *s
= expr_as_string (t
, 0);
3723 if (context
->show_column
)
3724 pp_verbatim (context
->printer
,
3725 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3726 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3728 pp_verbatim (context
->printer
,
3729 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3730 "locus", xloc
.file
, xloc
.line
, s
);
3731 pp_newline (context
->printer
);
3737 print_location (diagnostic_context
*context
, location_t loc
)
3739 expanded_location xloc
= expand_location (loc
);
3740 if (context
->show_column
)
3741 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3742 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3744 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3745 "locus", xloc
.file
, xloc
.line
);
3749 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3751 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3752 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3756 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3758 gcc_assert (concept_check_p (expr
));
3760 tree id
= unpack_concept_check (expr
);
3761 tree tmpl
= TREE_OPERAND (id
, 0);
3763 tmpl
= OVL_FIRST (tmpl
);
3765 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3767 cxx_pretty_printer
*pp
= (cxx_pretty_printer
*)context
->printer
;
3768 pp_verbatim (pp
, "required for the satisfaction of %qE", expr
);
3769 if (map
&& map
!= error_mark_node
)
3771 tree subst_map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3772 pp_cxx_parameter_mapping (pp
, (subst_map
!= error_mark_node
3773 ? subst_map
: map
));
3778 /* Diagnose the entry point into the satisfaction error. Returns the next
3782 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3784 tree src
= TREE_VALUE (cxt
);
3787 print_location (context
, input_location
);
3788 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3793 print_constrained_decl_info (context
, src
);
3798 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3799 return TREE_CHAIN (cxt
);
3804 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3807 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3808 tree map
= ATOMIC_CONSTR_MAP (constr
);
3809 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3810 if (map
== error_mark_node
)
3813 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3814 pp_verbatim (context
->printer
, "in requirements ");
3816 tree parms
= TREE_OPERAND (expr
, 0);
3818 pp_verbatim (context
->printer
, "with ");
3821 pp_verbatim (context
->printer
, "%q#D", parms
);
3822 if (TREE_CHAIN (parms
))
3823 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
3824 parms
= TREE_CHAIN (parms
);
3826 pp_cxx_parameter_mapping ((cxx_pretty_printer
*)context
->printer
, map
);
3828 pp_verbatim (context
->printer
, "\n");
3832 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
3837 tree constr
= TREE_VALUE (failed
);
3838 if (!constr
|| constr
== error_mark_node
)
3840 tree cxt
= CONSTR_CONTEXT (constr
);
3843 tree args
= TREE_PURPOSE (failed
);
3845 /* Print the stack of requirements. */
3846 cxt
= print_constraint_context_head (context
, cxt
, args
);
3847 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
3849 tree expr
= TREE_VALUE (cxt
);
3850 tree map
= TREE_PURPOSE (cxt
);
3851 print_concept_check_info (context
, expr
, map
, args
);
3852 cxt
= TREE_CHAIN (cxt
);
3855 /* For certain constraints, we can provide additional context. */
3856 if (TREE_CODE (constr
) == ATOMIC_CONSTR
3857 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
3858 print_requires_expression_info (context
, constr
, args
);
3862 maybe_print_constraint_context (diagnostic_context
*context
)
3864 if (!current_failed_constraint
)
3867 tree cur
= current_failed_constraint
;
3869 /* Recursively print nested contexts. */
3870 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
3871 if (current_failed_constraint
)
3872 maybe_print_constraint_context (context
);
3874 /* Print this context. */
3875 maybe_print_single_constraint_context (context
, cur
);
3878 /* Return true iff TYPE_A and TYPE_B are template types that are
3879 meaningful to compare. */
3882 comparable_template_types_p (tree type_a
, tree type_b
)
3884 if (!CLASS_TYPE_P (type_a
))
3886 if (!CLASS_TYPE_P (type_b
))
3889 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3890 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3891 if (!tinfo_a
|| !tinfo_b
)
3894 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3897 /* Start a new line indented by SPC spaces on PP. */
3900 newline_and_indent (pretty_printer
*pp
, int spc
)
3903 for (int i
= 0; i
< spc
; i
++)
3907 /* Generate a GC-allocated string for ARG, an expression or type. */
3910 arg_to_string (tree arg
, bool verbose
)
3913 return type_to_string (arg
, verbose
, true, NULL
, false);
3915 return expr_to_string (arg
);
3918 /* Subroutine to type_to_string_with_compare and
3919 print_template_tree_comparison.
3921 Print a representation of ARG (an expression or type) to PP,
3922 colorizing it as "type-diff" if PP->show_color. */
3925 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3927 pp_printf (pp
, "%r%s%R",
3930 ? arg_to_string (arg
, verbose
)
3931 : G_("(no argument)")));
3934 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3936 The types must satisfy comparable_template_types_p.
3938 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3939 potentially colorizing/eliding in comparison with TYPE_B.
3941 For example given types:
3942 vector<map<int,double>>
3944 vector<map<int,float>>
3945 then the result on PP would be:
3946 vector<map<[...],double>>
3947 with type elision, and:
3948 vector<map<int,double>>
3949 without type elision.
3951 In both cases the parts of TYPE that differ from PEER will be colorized
3952 if pp_show_color (pp) is true. In the above example, this would be
3955 If INDENT is non-zero, then the types are printed in a tree-like form
3956 which shows both types. In the above example, the result on PP would be:
3963 and without type-elision would be:
3970 As before, the differing parts of the types are colorized if
3971 pp_show_color (pp) is true ("double" and "float" in this example).
3973 Template arguments in which both types are using the default arguments
3974 are not printed; if at least one of the two types is using a non-default
3975 argument, then that argument is printed (or both arguments for the
3976 tree-like print format). */
3979 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3980 bool verbose
, int indent
)
3983 newline_and_indent (pp
, indent
);
3985 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3986 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3988 pp_printf (pp
, "%s<",
3989 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3991 tree args_a
= TI_ARGS (tinfo_a
);
3992 tree args_b
= TI_ARGS (tinfo_b
);
3993 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3994 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3996 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3997 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3998 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3999 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
4000 /* Determine the maximum range of args for which non-default template args
4001 were used; beyond this, only default args (if any) were used, and so
4002 they will be equal from this point onwards.
4003 One of the two peers might have used default arguments within this
4004 range, but the other will be using non-default arguments, and so
4005 it's more readable to print both within this range, to highlight
4007 int len_max
= MAX (len_a
, len_b
);
4008 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4009 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4010 for (int idx
= 0; idx
< len_max
; idx
++)
4013 pp_character (pp
, ',');
4015 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
4016 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
4020 newline_and_indent (pp
, indent
+ 2);
4021 /* Can do elision here, printing "[...]". */
4022 if (flag_elide_type
)
4023 pp_string (pp
, G_("[...]"));
4025 pp_string (pp
, arg_to_string (arg_a
, verbose
));
4029 int new_indent
= indent
? indent
+ 2 : 0;
4030 if (comparable_template_types_p (arg_a
, arg_b
))
4031 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
4035 newline_and_indent (pp
, indent
+ 2);
4036 pp_character (pp
, '[');
4037 print_nonequal_arg (pp
, arg_a
, verbose
);
4038 pp_string (pp
, " != ");
4039 print_nonequal_arg (pp
, arg_b
, verbose
);
4040 pp_character (pp
, ']');
4043 print_nonequal_arg (pp
, arg_a
, verbose
);
4046 pp_printf (pp
, ">");
4049 /* As type_to_string, but for a template, potentially colorizing/eliding
4050 in comparison with PEER.
4051 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4052 then the resulting string would be:
4054 with type elision, and:
4056 without type elision.
4058 In both cases the parts of TYPE that differ from PEER will be colorized
4059 if SHOW_COLOR is true. In the above example, this would be "double".
4061 Template arguments in which both types are using the default arguments
4062 are not printed; if at least one of the two types is using a non-default
4063 argument, then both arguments are printed.
4065 The resulting string is in a GC-allocated buffer. */
4068 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4071 pretty_printer inner_pp
;
4072 pretty_printer
*pp
= &inner_pp
;
4073 pp_show_color (pp
) = show_color
;
4075 print_template_differences (pp
, type
, peer
, verbose
, 0);
4076 return pp_ggc_formatted_text (pp
);
4079 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4080 indented by INDENT spaces.
4082 For example given types:
4084 vector<map<int,double>>
4088 vector<map<double,float>>
4090 the output with type elision would be:
4097 and without type-elision would be:
4104 TYPE_A and TYPE_B must both be comparable template types
4105 (as per comparable_template_types_p).
4107 Template arguments in which both types are using the default arguments
4108 are not printed; if at least one of the two types is using a non-default
4109 argument, then both arguments are printed. */
4112 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4113 bool verbose
, int indent
)
4115 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4118 /* Subroutine for use in a format_postprocessor::handle
4119 implementation. Adds a chunk to the end of
4120 formatted output, so that it will be printed
4121 by pp_output_formatted_text. */
4124 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4126 output_buffer
*buffer
= pp_buffer (pp
);
4127 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4128 const char **args
= chunk_array
->args
;
4130 unsigned int chunk_idx
;
4131 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4133 args
[chunk_idx
++] = content
;
4134 args
[chunk_idx
] = NULL
;
4137 /* Create a copy of CONTENT, with quotes added, and,
4138 potentially, with colorization.
4139 No escaped is performed on CONTENT.
4140 The result is in a GC-allocated buffer. */
4143 add_quotes (const char *content
, bool show_color
)
4145 pretty_printer tmp_pp
;
4146 pp_show_color (&tmp_pp
) = show_color
;
4148 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4149 quoting colorization bytes within the results. */
4150 pp_printf (&tmp_pp
, "%<%s%>", content
);
4152 return pp_ggc_formatted_text (&tmp_pp
);
4155 /* If we had %H and %I, and hence deferred printing them,
4156 print them now, storing the result into the chunk_info
4157 for pp_format. Quote them if 'q' was provided.
4158 Also print the difference in tree form, adding it as
4159 an additional chunk. */
4162 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4164 /* If we have one of %H and %I, the other should have
4166 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4168 /* Avoid reentrancy issues by working with a copy of
4169 m_type_a and m_type_b, resetting them now. */
4170 deferred_printed_type type_a
= m_type_a
;
4171 deferred_printed_type type_b
= m_type_b
;
4172 m_type_a
= deferred_printed_type ();
4173 m_type_b
= deferred_printed_type ();
4175 gcc_assert (type_a
.m_buffer_ptr
);
4176 gcc_assert (type_b
.m_buffer_ptr
);
4178 bool show_color
= pp_show_color (pp
);
4180 const char *type_a_text
;
4181 const char *type_b_text
;
4183 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4186 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4187 type_a
.m_verbose
, show_color
);
4189 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4190 type_b
.m_verbose
, show_color
);
4192 if (flag_diagnostics_show_template_tree
)
4194 pretty_printer inner_pp
;
4195 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4196 print_template_tree_comparison
4197 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4198 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4203 /* If the types were not comparable (or if only one of %H/%I was
4204 provided), they are printed normally, and no difference tree
4206 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4207 true, &type_a
.m_quote
, show_color
);
4208 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4209 true, &type_b
.m_quote
, show_color
);
4213 type_a_text
= add_quotes (type_a_text
, show_color
);
4214 *type_a
.m_buffer_ptr
= type_a_text
;
4217 type_b_text
= add_quotes (type_b_text
, show_color
);
4218 *type_b
.m_buffer_ptr
= type_b_text
;
4222 /* Subroutine for handling %H and %I, to support i18n of messages like:
4224 error_at (loc, "could not convert %qE from %qH to %qI",
4225 expr, type_a, type_b);
4227 so that we can print things like:
4229 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4231 and, with type-elision:
4233 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4235 (with color-coding of the differences between the types).
4237 The %H and %I format codes are peers: both must be present,
4238 and they affect each other. Hence to handle them, we must
4239 delay printing until we have both, deferring the printing to
4240 pretty_printer's m_format_postprocessor hook.
4242 This is called in phase 2 of pp_format, when it is accumulating
4243 a series of formatted chunks. We stash the location of the chunk
4244 we're meant to have written to, so that we can write to it in the
4245 m_format_postprocessor hook.
4247 We also need to stash whether a 'q' prefix was provided (the QUOTE
4248 param) so that we can add the quotes when writing out the delayed
4252 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4253 tree type
, const char **buffer_ptr
,
4254 bool verbose
, bool quote
)
4256 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4257 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4258 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4262 /* Called from output_format -- during diagnostic message processing --
4263 to handle C++ specific format specifier with the following meanings:
4264 %A function argument-list.
4268 %F function declaration.
4270 %H type difference (from).
4271 %I type difference (to).
4273 %L language as used in extern "lang".
4275 %P function parameter whose position is indicated by an integer.
4276 %Q assignment operator.
4277 %S substitution (template + args)
4280 %X exception-specification. */
4282 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4283 int precision
, bool wide
, bool set_locus
, bool verbose
,
4284 bool *quoted
, const char **buffer_ptr
)
4286 gcc_assert (pp
->m_format_postprocessor
);
4287 cxx_format_postprocessor
*postprocessor
4288 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4292 #define next_tree (t = va_arg (*text->args_ptr, tree))
4293 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4294 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4295 #define next_int va_arg (*text->args_ptr, int)
4297 if (precision
!= 0 || wide
)
4302 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4303 case 'C': result
= code_to_string (next_tcode
); break;
4306 tree temp
= next_tree
;
4308 && DECL_HAS_DEBUG_EXPR_P (temp
))
4310 temp
= DECL_DEBUG_EXPR (temp
);
4313 result
= expr_to_string (temp
);
4317 result
= decl_to_string (temp
, verbose
);
4320 case 'E': result
= expr_to_string (next_tree
); break;
4321 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4323 percent_G_format (text
);
4326 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4327 buffer_ptr
, verbose
, *quoted
);
4330 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4331 buffer_ptr
, verbose
, *quoted
);
4334 t
= va_arg (*text
->args_ptr
, tree
);
4335 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4337 case 'L': result
= language_to_string (next_lang
); break;
4338 case 'O': result
= op_to_string (false, next_tcode
); break;
4339 case 'P': result
= parm_to_string (next_int
); break;
4340 case 'Q': result
= op_to_string (true, next_tcode
); break;
4341 case 'S': result
= subst_to_string (next_tree
); break;
4344 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4345 pp_show_color (pp
));
4348 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4349 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4355 pp_string (pp
, result
);
4356 if (set_locus
&& t
!= NULL
)
4357 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4365 /* Warn about the use of C++0x features when appropriate. */
4367 maybe_warn_cpp0x (cpp0x_warn_str str
)
4369 if (cxx_dialect
== cxx98
)
4372 case CPP0X_INITIALIZER_LISTS
:
4373 pedwarn (input_location
, 0,
4374 "extended initializer lists "
4375 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4377 case CPP0X_EXPLICIT_CONVERSION
:
4378 pedwarn (input_location
, 0,
4379 "explicit conversion operators "
4380 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4382 case CPP0X_VARIADIC_TEMPLATES
:
4383 pedwarn (input_location
, 0,
4384 "variadic templates "
4385 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4387 case CPP0X_LAMBDA_EXPR
:
4388 pedwarn (input_location
, 0,
4389 "lambda expressions "
4390 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4393 pedwarn (input_location
, 0,
4394 "C++11 auto only available with %<-std=c++11%> or "
4395 "%<-std=gnu++11%>");
4397 case CPP0X_SCOPED_ENUMS
:
4398 pedwarn (input_location
, 0,
4399 "scoped enums only available with %<-std=c++11%> or "
4400 "%<-std=gnu++11%>");
4402 case CPP0X_DEFAULTED_DELETED
:
4403 pedwarn (input_location
, 0,
4404 "defaulted and deleted functions "
4405 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4407 case CPP0X_INLINE_NAMESPACES
:
4408 pedwarn (input_location
, OPT_Wpedantic
,
4409 "inline namespaces "
4410 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4412 case CPP0X_OVERRIDE_CONTROLS
:
4413 pedwarn (input_location
, 0,
4414 "override controls (override/final) "
4415 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4418 pedwarn (input_location
, 0,
4419 "non-static data member initializers "
4420 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4422 case CPP0X_USER_DEFINED_LITERALS
:
4423 pedwarn (input_location
, 0,
4424 "user-defined literals "
4425 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4427 case CPP0X_DELEGATING_CTORS
:
4428 pedwarn (input_location
, 0,
4429 "delegating constructors "
4430 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4432 case CPP0X_INHERITING_CTORS
:
4433 pedwarn (input_location
, 0,
4434 "inheriting constructors "
4435 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4437 case CPP0X_ATTRIBUTES
:
4438 pedwarn (input_location
, 0,
4440 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4442 case CPP0X_REF_QUALIFIER
:
4443 pedwarn (input_location
, 0,
4445 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4452 /* Warn about the use of variadic templates when appropriate. */
4454 maybe_warn_variadic_templates (void)
4456 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4460 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4461 option OPT with text GMSGID. Use this function to report
4462 diagnostics for constructs that are invalid C++98, but valid
4465 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4467 diagnostic_info diagnostic
;
4470 rich_location
richloc (line_table
, location
);
4472 va_start (ap
, gmsgid
);
4473 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4474 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4475 diagnostic
.option_index
= opt
;
4476 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4481 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4482 we found when we tried to do the lookup. LOCATION is the location of
4483 the NAME identifier. */
4486 qualified_name_lookup_error (tree scope
, tree name
,
4487 tree decl
, location_t location
)
4489 if (scope
== error_mark_node
)
4490 ; /* We already complained. */
4491 else if (TYPE_P (scope
))
4493 if (!COMPLETE_TYPE_P (scope
))
4494 error_at (location
, "incomplete type %qT used in nested name specifier",
4496 else if (TREE_CODE (decl
) == TREE_LIST
)
4498 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4500 print_candidates (decl
);
4505 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4506 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4507 if (const char *suggestion
= hint
.suggestion ())
4509 gcc_rich_location
richloc (location
);
4510 richloc
.add_fixit_replace (suggestion
);
4512 "%qD is not a member of %qT; did you mean %qs?",
4513 name
, scope
, suggestion
);
4516 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4519 else if (scope
!= global_namespace
)
4521 auto_diagnostic_group d
;
4522 bool emit_fixit
= true;
4524 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4527 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4528 /* "location" is just the location of the name, not of the explicit
4529 scope, and it's not easy to get at the latter, so we can't issue
4530 fix-it hints for the suggestion. */
4533 if (const char *suggestion
= hint
.suggestion ())
4535 gcc_rich_location
richloc (location
);
4537 richloc
.add_fixit_replace (suggestion
);
4538 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4539 name
, scope
, suggestion
);
4542 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4546 auto_diagnostic_group d
;
4547 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4548 if (const char *suggestion
= hint
.suggestion ())
4550 gcc_rich_location
richloc (location
);
4551 richloc
.add_fixit_replace (suggestion
);
4553 "%<::%D%> has not been declared; did you mean %qs?",
4557 error_at (location
, "%<::%D%> has not been declared", name
);
4561 /* C++-specific implementation of range_label::get_text () vfunc for
4562 range_label_for_type_mismatch.
4564 Compare with print_template_differences above. */
4567 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4569 if (m_labelled_type
== NULL_TREE
)
4570 return label_text::borrow (NULL
);
4572 const bool verbose
= false;
4573 const bool show_color
= false;
4577 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4578 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4579 verbose
, show_color
);
4581 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4583 /* Both of the above return GC-allocated buffers, so the caller mustn't
4585 return label_text::borrow (result
);