1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2022 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_MEMORY
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 an '@module' name suffix for DECL, if any. */
185 dump_module_suffix (cxx_pretty_printer
*pp
, tree decl
)
190 if (!DECL_CONTEXT (decl
))
193 if (TREE_CODE (decl
) != CONST_DECL
194 || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl
)))
196 if (!DECL_NAMESPACE_SCOPE_P (decl
))
199 if (TREE_CODE (decl
) == NAMESPACE_DECL
200 && !DECL_NAMESPACE_ALIAS (decl
)
201 && (TREE_PUBLIC (decl
) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl
))))
205 if (unsigned m
= get_originating_module (decl
))
206 if (const char *n
= module_name (m
, false))
208 pp_character (pp
, '@');
209 pp
->padding
= pp_none
;
214 /* The scope of the declaration we're currently printing, to avoid redundantly
215 dumping the same scope on parameter types. */
216 static tree current_dump_scope
;
218 /* Dump a scope, if deemed necessary. */
221 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
223 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
225 if (scope
== NULL_TREE
|| scope
== current_dump_scope
)
228 /* Enum values within an unscoped enum will be CONST_DECL with an
229 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
230 ENUMERAL_TYPE, so as to print any enclosing namespace. */
231 if (UNSCOPED_ENUM_P (scope
))
232 scope
= CP_TYPE_CONTEXT (scope
);
234 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
236 if (scope
!= global_namespace
)
238 dump_decl (pp
, scope
, f
);
239 pp_cxx_colon_colon (pp
);
242 else if (AGGREGATE_TYPE_P (scope
)
243 || SCOPED_ENUM_P (scope
))
245 dump_type (pp
, scope
, f
);
246 pp_cxx_colon_colon (pp
);
248 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
250 dump_function_decl (pp
, scope
, f
| TFF_NO_TEMPLATE_BINDINGS
);
251 pp_cxx_colon_colon (pp
);
255 /* Dump the template ARGument under control of FLAGS. */
258 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
260 if (ARGUMENT_PACK_P (arg
))
261 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
262 /* No default args in argument packs. */
263 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
264 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
265 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
268 if (TREE_CODE (arg
) == TREE_LIST
)
269 arg
= TREE_VALUE (arg
);
271 /* Strip implicit conversions. */
272 while (CONVERT_EXPR_P (arg
))
273 arg
= TREE_OPERAND (arg
, 0);
275 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
279 /* Count the number of template arguments ARGS whose value does not
280 match the (optional) default template parameter in PARAMS */
283 get_non_default_template_args_count (tree args
, int flags
)
285 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
287 if (/* We use this flag when generating debug information. We don't
288 want to expand templates at this point, for this may generate
289 new decls, which gets decl counts out of sync, which may in
290 turn cause codegen differences between compilations with and
292 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
293 || !flag_pretty_templates
)
296 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
299 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
303 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
305 int n
= get_non_default_template_args_count (args
, flags
);
309 for (i
= 0; i
< n
; ++i
)
311 tree arg
= TREE_VEC_ELT (args
, i
);
313 /* Only print a comma if we know there is an argument coming. In
314 the case of an empty template argument pack, no actual
315 argument will be printed. */
317 && (!ARGUMENT_PACK_P (arg
)
318 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
319 pp_separate_with_comma (pp
);
321 dump_template_argument (pp
, arg
, flags
);
326 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
329 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
334 if (parm
== error_mark_node
)
337 p
= TREE_VALUE (parm
);
338 a
= TREE_PURPOSE (parm
);
340 if (TREE_CODE (p
) == TYPE_DECL
)
342 if (flags
& TFF_DECL_SPECIFIERS
)
344 pp_cxx_ws_string (pp
, "class");
345 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
346 pp_cxx_ws_string (pp
, "...");
348 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
350 else if (DECL_NAME (p
))
351 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
353 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
356 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
358 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
360 pp_cxx_whitespace (pp
);
362 pp_cxx_whitespace (pp
);
363 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
364 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
366 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
370 /* Dump, under control of FLAGS, a template-parameter-list binding.
371 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
375 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
376 vec
<tree
, va_gc
> *typenames
)
378 /* Print "[with" and ']', conditional on whether anything is printed at all.
379 This is tied to whether a semicolon is needed to separate multiple template
381 struct prepost_semicolon
383 cxx_pretty_printer
*pp
;
389 pp_separate_with_semicolon (pp
);
392 pp_cxx_whitespace (pp
);
393 pp_cxx_left_bracket (pp
);
394 pp
->translate_string ("with");
395 pp_cxx_whitespace (pp
);
396 need_semicolon
= true;
400 ~prepost_semicolon ()
403 pp_cxx_right_bracket (pp
);
405 } semicolon_or_introducer
= {pp
, false};
412 tree p
= TREE_VALUE (parms
);
413 int lvl
= TMPL_PARMS_DEPTH (parms
);
416 tree lvl_args
= NULL_TREE
;
418 /* Don't crash if we had an invalid argument list. */
419 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
420 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
422 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
424 tree arg
= NULL_TREE
;
426 /* Don't crash if we had an invalid argument list. */
427 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
428 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
430 tree parm_i
= TREE_VEC_ELT (p
, i
);
431 /* If the template argument repeats the template parameter (T = T),
432 skip the parameter.*/
433 if (arg
&& TREE_CODE (arg
) == TEMPLATE_TYPE_PARM
434 && TREE_CODE (parm_i
) == TREE_LIST
435 && TREE_CODE (TREE_VALUE (parm_i
)) == TYPE_DECL
436 && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i
)))
437 == TEMPLATE_TYPE_PARM
438 && DECL_NAME (TREE_VALUE (parm_i
))
439 == DECL_NAME (TREE_CHAIN (arg
)))
442 semicolon_or_introducer ();
443 dump_template_parameter (pp
, parm_i
, TFF_PLAIN_IDENTIFIER
);
444 pp_cxx_whitespace (pp
);
446 pp_cxx_whitespace (pp
);
449 if (ARGUMENT_PACK_P (arg
))
450 pp_cxx_left_brace (pp
);
451 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
452 if (ARGUMENT_PACK_P (arg
))
453 pp_cxx_right_brace (pp
);
456 pp_string (pp
, M_("<missing>"));
461 parms
= TREE_CHAIN (parms
);
464 /* Don't bother with typenames for a partial instantiation. */
465 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
468 /* Don't try to print typenames when we're processing a clone. */
469 if (current_function_decl
470 && !DECL_LANG_SPECIFIC (current_function_decl
))
473 /* Don't try to do this once cgraph starts throwing away front-end
478 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
480 semicolon_or_introducer ();
481 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
482 pp_cxx_whitespace (pp
);
484 pp_cxx_whitespace (pp
);
485 push_deferring_access_checks (dk_no_check
);
486 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
487 pop_deferring_access_checks ();
488 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
489 pp_simple_type_specifier doesn't know about it. */
490 t
= strip_typedefs (t
, NULL
, STF_USER_VISIBLE
);
491 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
495 /* Dump a human-readable equivalent of the alias template
496 specialization of T. */
499 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
501 gcc_assert (alias_template_specialization_p (t
, nt_opaque
));
503 tree decl
= TYPE_NAME (t
);
504 if (!(flags
& TFF_UNQUALIFIED_NAME
))
505 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
506 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
507 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
509 flags
& ~TFF_TEMPLATE_HEADER
);
512 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
516 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
521 /* Don't print e.g. "struct mytypedef". */
522 if (TYPE_P (t
) && typedef_variant_p (t
))
524 tree decl
= TYPE_NAME (t
);
525 if ((flags
& TFF_CHASE_TYPEDEF
)
526 || DECL_SELF_REFERENCE_P (decl
)
527 || (!flag_pretty_templates
528 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
530 unsigned int stf_flags
= (!(pp
->flags
& pp_c_flag_gnu_v3
)
531 ? STF_USER_VISIBLE
: 0);
532 t
= strip_typedefs (t
, NULL
, stf_flags
);
534 else if (alias_template_specialization_p (t
, nt_opaque
))
536 dump_alias_template_specialization (pp
, t
, flags
);
539 else if (same_type_p (t
, TREE_TYPE (decl
)))
543 pp_cxx_cv_qualifier_seq (pp
, t
);
544 if (! (flags
& TFF_UNQUALIFIED_NAME
))
545 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
546 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
551 if (TYPE_PTRMEMFUNC_P (t
))
554 switch (TREE_CODE (t
))
557 if (t
== init_list_type_node
)
558 pp_string (pp
, M_("<brace-enclosed initializer list>"));
559 else if (t
== unknown_type_node
)
560 pp_string (pp
, M_("<unresolved overloaded function type>"));
563 pp_cxx_cv_qualifier_seq (pp
, t
);
564 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
569 /* A list of function parms. */
570 dump_parameters (pp
, t
, flags
);
573 case IDENTIFIER_NODE
:
574 pp_cxx_tree_identifier (pp
, t
);
578 dump_type (pp
, BINFO_TYPE (t
), flags
);
584 dump_aggr_type (pp
, t
, flags
);
588 if (flags
& TFF_CHASE_TYPEDEF
)
590 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
591 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
598 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
608 case FIXED_POINT_TYPE
:
609 pp_type_specifier_seq (pp
, t
);
612 case TEMPLATE_TEMPLATE_PARM
:
613 /* For parameters inside template signature. */
614 if (TYPE_IDENTIFIER (t
))
615 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
617 pp_cxx_canonical_template_parameter (pp
, t
);
620 case BOUND_TEMPLATE_TEMPLATE_PARM
:
622 tree args
= TYPE_TI_ARGS (t
);
623 pp_cxx_cv_qualifier_seq (pp
, t
);
624 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
625 pp_cxx_begin_template_argument_list (pp
);
626 dump_template_argument_list (pp
, args
, flags
);
627 pp_cxx_end_template_argument_list (pp
);
631 case TEMPLATE_TYPE_PARM
:
632 pp_cxx_cv_qualifier_seq (pp
, t
);
633 if (template_placeholder_p (t
))
635 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
636 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
637 pp_string (pp
, "<...auto...>");
639 else if (TYPE_IDENTIFIER (t
))
640 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
642 pp_cxx_canonical_template_parameter
643 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
644 /* If this is a constrained placeholder, add the requirements. */
645 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
646 pp_cxx_constrained_type_spec (pp
, c
);
649 /* This is not always necessary for pointers and such, but doing this
650 reduces code size. */
659 dump_type_prefix (pp
, t
, flags
);
660 dump_type_suffix (pp
, t
, flags
);
664 if (! (flags
& TFF_CHASE_TYPEDEF
)
665 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
667 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
670 pp_cxx_cv_qualifier_seq (pp
, t
);
671 pp_cxx_ws_string (pp
,
672 TYPENAME_IS_ENUM_P (t
) ? "enum"
673 : TYPENAME_IS_CLASS_P (t
) ? "class"
675 dump_typename (pp
, t
, flags
);
678 case UNBOUND_CLASS_TEMPLATE
:
679 if (! (flags
& TFF_UNQUALIFIED_NAME
))
681 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
682 pp_cxx_colon_colon (pp
);
684 pp_cxx_ws_string (pp
, "template");
685 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
689 pp_cxx_ws_string (pp
, "__typeof__");
690 pp_cxx_whitespace (pp
);
691 pp_cxx_left_paren (pp
);
692 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
693 pp_cxx_right_paren (pp
);
696 case UNDERLYING_TYPE
:
697 pp_cxx_ws_string (pp
, "__underlying_type");
698 pp_cxx_whitespace (pp
);
699 pp_cxx_left_paren (pp
);
700 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
701 pp_cxx_right_paren (pp
);
704 case TYPE_PACK_EXPANSION
:
705 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
706 pp_cxx_ws_string (pp
, "...");
709 case TYPE_ARGUMENT_PACK
:
710 dump_template_argument (pp
, t
, flags
);
714 pp_cxx_ws_string (pp
, "decltype");
715 pp_cxx_whitespace (pp
);
716 pp_cxx_left_paren (pp
);
717 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
718 pp_cxx_right_paren (pp
);
722 pp_string (pp
, "std::nullptr_t");
726 pp_unsupported_tree (pp
, t
);
730 pp_string (pp
, M_("<type error>"));
735 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
739 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
741 tree ctx
= TYPE_CONTEXT (t
);
743 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
744 dump_typename (pp
, ctx
, flags
);
746 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
747 pp_cxx_colon_colon (pp
);
748 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
751 /* Return the name of the supplied aggregate, or enumeral type. */
754 class_key_or_enum_as_string (tree t
)
756 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
758 if (SCOPED_ENUM_P (t
))
763 else if (TREE_CODE (t
) == UNION_TYPE
)
765 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
771 /* Disable warnings about missing quoting in GCC diagnostics for
772 the pp_verbatim call. Their format strings deliberately don't
773 follow GCC diagnostic conventions. */
775 #pragma GCC diagnostic push
776 #pragma GCC diagnostic ignored "-Wformat-diag"
779 /* Print out a class declaration T under the control of FLAGS,
780 in the form `class foo'. */
783 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
785 const char *variety
= class_key_or_enum_as_string (t
);
789 pp_cxx_cv_qualifier_seq (pp
, t
);
791 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
792 pp_cxx_ws_string (pp
, variety
);
794 tree decl
= TYPE_NAME (t
);
798 typdef
= (!DECL_ARTIFICIAL (decl
)
799 /* An alias specialization is not considered to be a
801 && !alias_template_specialization_p (t
, nt_opaque
));
804 && ((flags
& TFF_CHASE_TYPEDEF
)
805 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (decl
)
806 && DECL_TEMPLATE_INFO (decl
))))
807 || DECL_SELF_REFERENCE_P (decl
))
809 t
= TYPE_MAIN_VARIANT (t
);
810 decl
= TYPE_NAME (t
);
814 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
815 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
816 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
817 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
819 if (! (flags
& TFF_UNQUALIFIED_NAME
))
820 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
| TFF_SCOPE
);
821 flags
&= ~TFF_UNQUALIFIED_NAME
;
824 /* Because the template names are mangled, we have to locate
825 the most general template, and use that name. */
826 tree tpl
= TYPE_TI_TEMPLATE (t
);
828 while (DECL_TEMPLATE_INFO (tpl
))
829 tpl
= DECL_TI_TEMPLATE (tpl
);
834 if (LAMBDA_TYPE_P (t
))
836 /* A lambda's "type" is essentially its signature. */
837 pp_string (pp
, M_("<lambda"));
838 if (lambda_function (t
))
840 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
844 else if (!decl
|| IDENTIFIER_ANON_P (DECL_NAME (decl
)))
846 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
847 pp_string (pp
, M_("<unnamed>"));
849 pp_printf (pp
, M_("<unnamed %s>"), variety
);
852 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
854 dump_module_suffix (pp
, decl
);
857 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
858 !CLASSTYPE_USE_TEMPLATE (t
),
859 flags
& ~TFF_TEMPLATE_HEADER
);
863 #pragma GCC diagnostic pop
866 /* Dump into the obstack the initial part of the output for a given type.
867 This is necessary when dealing with things like functions returning
870 return type of `int (* fee ())()': pointer -> function -> int. Both
871 pointer (and reference and offset) and function (and member) types must
872 deal with prefix and suffix.
874 Arrays must also do this for DECL nodes, like int a[], and for things like
878 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
880 if (TYPE_PTRMEMFUNC_P (t
))
882 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
886 switch (TREE_CODE (t
))
891 tree sub
= TREE_TYPE (t
);
893 dump_type_prefix (pp
, sub
, flags
);
894 if (TREE_CODE (sub
) == ARRAY_TYPE
895 || TREE_CODE (sub
) == FUNCTION_TYPE
)
897 pp_cxx_whitespace (pp
);
898 pp_cxx_left_paren (pp
);
899 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
903 else if (TYPE_REF_P (t
))
905 if (TYPE_REF_IS_RVALUE (t
))
906 pp_ampersand_ampersand (pp
);
910 pp
->padding
= pp_before
;
911 pp_cxx_cv_qualifier_seq (pp
, t
);
917 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
918 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
921 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
922 pp_cxx_left_paren (pp
);
923 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
924 pp_cxx_colon_colon (pp
);
927 pp_cxx_cv_qualifier_seq (pp
, t
);
928 pp
->padding
= pp_before
;
931 /* This can be reached without a pointer when dealing with
932 templates, e.g. std::is_function. */
934 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
938 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
940 pp_cxx_left_paren (pp
);
941 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
942 pp_cxx_colon_colon (pp
);
946 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
950 case IDENTIFIER_NODE
:
955 case TEMPLATE_TYPE_PARM
:
956 case TEMPLATE_TEMPLATE_PARM
:
957 case BOUND_TEMPLATE_TEMPLATE_PARM
:
969 case UNDERLYING_TYPE
:
971 case TYPE_PACK_EXPANSION
:
972 case FIXED_POINT_TYPE
:
974 dump_type (pp
, t
, flags
);
975 pp
->padding
= pp_before
;
979 pp_unsupported_tree (pp
, t
);
982 pp_string (pp
, M_("<typeprefixerror>"));
987 /* Dump the suffix of type T, under control of FLAGS. This is the part
988 which appears after the identifier (or function parms). */
991 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
993 if (TYPE_PTRMEMFUNC_P (t
))
994 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
996 switch (TREE_CODE (t
))
1001 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1002 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1003 pp_cxx_right_paren (pp
);
1004 if (TREE_CODE (t
) == POINTER_TYPE
)
1005 flags
|= TFF_POINTER
;
1006 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1013 if (TREE_CODE (t
) == METHOD_TYPE
)
1014 /* Can only be reached through a pointer. */
1015 pp_cxx_right_paren (pp
);
1016 arg
= TYPE_ARG_TYPES (t
);
1017 if (TREE_CODE (t
) == METHOD_TYPE
)
1018 arg
= TREE_CHAIN (arg
);
1020 /* Function pointers don't have default args. Not in standard C++,
1021 anyway; they may in g++, but we'll just pretend otherwise. */
1022 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
1024 pp
->padding
= pp_before
;
1025 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
1026 TREE_CODE (t
) == FUNCTION_TYPE
1027 && (flags
& TFF_POINTER
));
1028 dump_ref_qualifier (pp
, t
, flags
);
1029 if (tx_safe_fn_type_p (t
))
1030 pp_cxx_ws_string (pp
, "transaction_safe");
1031 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
1032 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1037 pp_maybe_space (pp
);
1038 pp_cxx_left_bracket (pp
);
1039 if (tree dtype
= TYPE_DOMAIN (t
))
1041 tree max
= TYPE_MAX_VALUE (dtype
);
1042 /* Zero-length arrays have a null upper bound in C and SIZE_MAX
1043 in C++. Handle both since the type might be constructed by
1044 the middle end and end up here as a result of a warning (see
1046 if (!max
|| integer_all_onesp (max
))
1047 pp_character (pp
, '0');
1048 else if (tree_fits_shwi_p (max
))
1049 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
1053 if (TREE_CODE (max
) == SAVE_EXPR
)
1054 max
= TREE_OPERAND (max
, 0);
1055 if (TREE_CODE (max
) == MINUS_EXPR
1056 || TREE_CODE (max
) == PLUS_EXPR
)
1058 max
= TREE_OPERAND (max
, 0);
1059 while (CONVERT_EXPR_P (max
))
1060 max
= TREE_OPERAND (max
, 0);
1063 max
= fold_build2_loc (input_location
,
1064 PLUS_EXPR
, dtype
, max
,
1065 build_int_cst (dtype
, 1));
1066 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
1069 pp_cxx_right_bracket (pp
);
1070 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1074 case IDENTIFIER_NODE
:
1079 case TEMPLATE_TYPE_PARM
:
1080 case TEMPLATE_TEMPLATE_PARM
:
1081 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1093 case UNDERLYING_TYPE
:
1095 case TYPE_PACK_EXPANSION
:
1096 case FIXED_POINT_TYPE
:
1101 pp_unsupported_tree (pp
, t
);
1103 /* Don't mark it here, we should have already done in
1104 dump_type_prefix. */
1110 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1112 const char *p
= NULL
;
1114 if (DECL_GLOBAL_CTOR_P (t
))
1115 p
= M_("(static initializers for %s)");
1116 else if (DECL_GLOBAL_DTOR_P (t
))
1117 p
= M_("(static destructors for %s)");
1121 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1125 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1127 if (template_parm_object_p (t
))
1128 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1130 if (flags
& TFF_DECL_SPECIFIERS
)
1132 if (concept_definition_p (t
))
1133 pp_cxx_ws_string (pp
, "concept");
1134 else if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1135 pp_cxx_ws_string (pp
, "constexpr");
1137 if (!standard_concept_p (t
))
1138 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1139 pp_maybe_space (pp
);
1141 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1142 && TREE_CODE (t
) != PARM_DECL
1143 && (!DECL_INITIAL (t
)
1144 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1145 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1146 flags
&= ~TFF_UNQUALIFIED_NAME
;
1147 if ((flags
& TFF_DECL_SPECIFIERS
)
1148 && DECL_TEMPLATE_PARM_P (t
)
1149 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1150 pp_string (pp
, "...");
1153 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1156 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1157 pp_string (pp
, " capture>");
1160 dump_decl (pp
, DECL_NAME (t
), flags
);
1162 else if (DECL_DECOMPOSITION_P (t
))
1163 pp_string (pp
, M_("<structured bindings>"));
1165 pp_string (pp
, M_("<anonymous>"));
1167 dump_module_suffix (pp
, t
);
1169 if (flags
& TFF_DECL_SPECIFIERS
)
1170 dump_type_suffix (pp
, type
, flags
);
1173 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1176 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1178 /* These special cases are duplicated here so that other functions
1179 can feed identifiers to error and get them demangled properly. */
1180 if (IDENTIFIER_CONV_OP_P (t
))
1182 pp_cxx_ws_string (pp
, "operator");
1183 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1184 dump_type (pp
, TREE_TYPE (t
), flags
);
1187 if (dguide_name_p (t
))
1189 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1190 TFF_UNQUALIFIED_NAME
);
1194 const char *str
= IDENTIFIER_POINTER (t
);
1195 if (startswith (str
, "_ZGR"))
1197 pp_cxx_ws_string (pp
, "<temporary>");
1201 pp_cxx_tree_identifier (pp
, t
);
1204 /* Dump a human readable string for the decl T under control of FLAGS. */
1207 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1212 /* If doing Objective-C++, give Objective-C a chance to demangle
1213 Objective-C method names. */
1214 if (c_dialect_objc ())
1216 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1219 pp_string (pp
, demangled
);
1224 switch (TREE_CODE (t
))
1227 /* Don't say 'typedef class A' */
1228 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1230 if ((flags
& TFF_DECL_SPECIFIERS
)
1231 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1233 /* Say `class T' not just `T'. */
1234 pp_cxx_ws_string (pp
, "class");
1236 /* Emit the `...' for a parameter pack. */
1237 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1238 pp_cxx_ws_string (pp
, "...");
1241 dump_type (pp
, TREE_TYPE (t
), flags
);
1244 if (TYPE_DECL_ALIAS_P (t
)
1245 && (flags
& TFF_DECL_SPECIFIERS
1246 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1248 pp_cxx_ws_string (pp
, "using");
1249 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1250 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1251 dump_decl (pp
, DECL_NAME (t
), flags
);
1252 pp_cxx_whitespace (pp
);
1253 pp_cxx_ws_string (pp
, "=");
1254 pp_cxx_whitespace (pp
);
1255 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1256 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1260 if ((flags
& TFF_DECL_SPECIFIERS
)
1261 && !DECL_SELF_REFERENCE_P (t
))
1262 pp_cxx_ws_string (pp
, "typedef");
1263 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1264 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1269 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1271 pp_string (pp
, M_("vtable for "));
1272 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1273 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1279 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1281 /* Handle variable template specializations. */
1283 && DECL_LANG_SPECIFIC (t
)
1284 && DECL_TEMPLATE_INFO (t
)
1285 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1287 pp_cxx_begin_template_argument_list (pp
);
1288 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1289 dump_template_argument_list (pp
, args
, flags
);
1290 pp_cxx_end_template_argument_list (pp
);
1295 pp_string (pp
, M_("<return value> "));
1296 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1299 case NAMESPACE_DECL
:
1300 if (flags
& TFF_DECL_SPECIFIERS
)
1301 pp
->declaration (t
);
1304 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1305 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1306 flags
&= ~TFF_UNQUALIFIED_NAME
;
1307 if (DECL_NAME (t
) == NULL_TREE
)
1309 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1310 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1312 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1315 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1320 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1321 pp_cxx_colon_colon (pp
);
1322 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1326 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1327 pp_cxx_left_bracket (pp
);
1328 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1329 pp_cxx_right_bracket (pp
);
1332 /* So that we can do dump_decl on an aggr type. */
1336 dump_type (pp
, t
, flags
);
1340 /* This is a pseudo destructor call which has not been folded into
1341 a PSEUDO_DTOR_EXPR yet. */
1342 pp_cxx_complement (pp
);
1343 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1350 case IDENTIFIER_NODE
:
1351 dump_decl_name (pp
, t
, flags
);
1355 if (!OVL_SINGLE_P (t
))
1357 tree ctx
= ovl_scope (t
);
1358 if (ctx
!= global_namespace
)
1361 dump_type (pp
, ctx
, flags
);
1363 dump_decl (pp
, ctx
, flags
);
1364 pp_cxx_colon_colon (pp
);
1366 dump_decl (pp
, OVL_NAME (t
), flags
);
1370 /* If there's only one function, just treat it like an ordinary
1376 if (! DECL_LANG_SPECIFIC (t
))
1378 if (DECL_ABSTRACT_ORIGIN (t
)
1379 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1380 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1382 dump_function_name (pp
, t
, flags
);
1384 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1385 dump_global_iord (pp
, t
);
1387 dump_function_decl (pp
, t
, flags
);
1391 dump_template_decl (pp
, t
, flags
);
1395 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1399 pp_string (pp
, "<wildcard>");
1402 case TEMPLATE_ID_EXPR
:
1404 tree name
= TREE_OPERAND (t
, 0);
1405 tree args
= TREE_OPERAND (t
, 1);
1407 if (!identifier_p (name
))
1408 name
= OVL_NAME (name
);
1409 dump_decl (pp
, name
, flags
);
1410 pp_cxx_begin_template_argument_list (pp
);
1411 if (args
== error_mark_node
)
1412 pp_string (pp
, M_("<template arguments error>"));
1414 dump_template_argument_list
1415 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1416 pp_cxx_end_template_argument_list (pp
);
1422 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1424 dump_generic_node (pp
, t
, 0, TDF_SLIM
, false);
1428 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1429 || (DECL_INITIAL (t
) &&
1430 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1431 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1432 else if (DECL_NAME (t
))
1433 dump_decl (pp
, DECL_NAME (t
), flags
);
1434 else if (DECL_INITIAL (t
))
1435 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1437 pp_string (pp
, M_("<enumerator>"));
1442 pp_cxx_ws_string (pp
, "using");
1443 tree scope
= USING_DECL_SCOPE (t
);
1444 bool variadic
= false;
1445 if (PACK_EXPANSION_P (scope
))
1447 scope
= PACK_EXPANSION_PATTERN (scope
);
1450 dump_type (pp
, scope
, flags
);
1451 pp_cxx_colon_colon (pp
);
1452 dump_decl (pp
, DECL_NAME (t
), flags
);
1454 pp_cxx_ws_string (pp
, "...");
1459 pp
->declaration (t
);
1463 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1466 case NON_DEPENDENT_EXPR
:
1467 dump_expr (pp
, t
, flags
);
1470 case TEMPLATE_TYPE_PARM
:
1471 if (flags
& TFF_DECL_SPECIFIERS
)
1472 pp
->declaration (t
);
1477 case UNBOUND_CLASS_TEMPLATE
:
1478 case TYPE_PACK_EXPANSION
:
1480 dump_type (pp
, t
, flags
);
1484 pp_unsupported_tree (pp
, t
);
1488 pp_string (pp
, M_("<declaration error>"));
1493 /* Dump a template declaration T under control of FLAGS. This means the
1494 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1497 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1499 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1503 if (flags
& TFF_TEMPLATE_HEADER
)
1505 for (parms
= orig_parms
= nreverse (orig_parms
);
1507 parms
= TREE_CHAIN (parms
))
1509 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1510 int len
= TREE_VEC_LENGTH (inner_parms
);
1514 /* Skip over the dummy template levels of a template template
1516 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1520 pp_cxx_ws_string (pp
, "template");
1521 pp_cxx_begin_template_argument_list (pp
);
1523 /* If we've shown the template prefix, we'd better show the
1524 parameters' and decl's type too. */
1525 flags
|= TFF_DECL_SPECIFIERS
;
1527 for (i
= 0; i
< len
; i
++)
1530 pp_separate_with_comma (pp
);
1531 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1534 pp_cxx_end_template_argument_list (pp
);
1535 pp_cxx_whitespace (pp
);
1537 nreverse(orig_parms
);
1539 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1541 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1542 pp_cxx_ws_string (pp
, "class");
1544 /* If this is a parameter pack, print the ellipsis. */
1545 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1546 pp_cxx_ws_string (pp
, "...");
1549 /* Only print the requirements if we're also printing
1550 the template header. */
1552 if (tree ci
= get_constraints (t
))
1553 if (check_constraint_info (ci
))
1554 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1556 pp_cxx_requires_clause (pp
, reqs
);
1557 pp_cxx_whitespace (pp
);
1562 if (DECL_CLASS_TEMPLATE_P (t
))
1563 dump_type (pp
, TREE_TYPE (t
),
1564 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1565 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1566 else if (DECL_TEMPLATE_RESULT (t
)
1567 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1568 /* Alias template. */
1569 || DECL_TYPE_TEMPLATE_P (t
)
1570 /* Concept definition. &*/
1571 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1572 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1575 gcc_assert (TREE_TYPE (t
));
1576 switch (NEXT_CODE (t
))
1580 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1583 /* This case can occur with some invalid code. */
1584 dump_type (pp
, TREE_TYPE (t
),
1585 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1586 | (flags
& TFF_DECL_SPECIFIERS
1587 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1592 /* find_typenames looks through the type of the function template T
1593 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1596 struct find_typenames_t
1598 hash_set
<tree
> *p_set
;
1599 vec
<tree
, va_gc
> *typenames
;
1603 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1605 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1606 tree mv
= NULL_TREE
;
1608 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1609 /* Add the type of the typedef without any additional cv-quals. */
1610 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1611 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1612 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1613 /* Add the typename without any cv-qualifiers. */
1614 mv
= TYPE_MAIN_VARIANT (*tp
);
1616 if (PACK_EXPANSION_P (*tp
))
1618 /* Don't mess with parameter packs since we don't remember
1619 the pack expansion context for a particular typename. */
1620 *walk_subtrees
= false;
1624 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1625 vec_safe_push (d
->typenames
, mv
);
1630 static vec
<tree
, va_gc
> *
1631 find_typenames (tree t
)
1633 struct find_typenames_t ft
;
1634 ft
.p_set
= new hash_set
<tree
>;
1635 ft
.typenames
= NULL
;
1636 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1637 find_typenames_r
, &ft
, ft
.p_set
);
1639 return ft
.typenames
;
1642 /* Output the "[with ...]" clause for a template instantiation T iff
1643 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1644 formatting a deduction/substitution diagnostic rather than an
1648 dump_substitution (cxx_pretty_printer
*pp
,
1649 tree t
, tree template_parms
, tree template_args
,
1652 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1653 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1655 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1656 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1660 /* Dump the lambda function FN including its 'mutable' qualifier and any
1661 template bindings. */
1664 dump_lambda_function (cxx_pretty_printer
*pp
,
1665 tree fn
, tree template_parms
, tree template_args
,
1668 /* A lambda's signature is essentially its "type". */
1669 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1670 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1672 pp
->padding
= pp_before
;
1673 pp_c_ws_string (pp
, "mutable");
1675 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1678 /* Pretty print a function decl. There are several ways we want to print a
1679 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1680 As error can only apply the '#' flag once to give 0 and 1 for V, there
1681 is %D which doesn't print the throw specs, and %F which does. */
1684 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1688 tree cname
= NULL_TREE
;
1689 tree template_args
= NULL_TREE
;
1690 tree template_parms
= NULL_TREE
;
1691 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1692 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1695 tree ret
= NULL_TREE
;
1697 int dump_function_name_flags
= flags
& ~TFF_UNQUALIFIED_NAME
;
1698 flags
= dump_function_name_flags
& ~TFF_TEMPLATE_NAME
;
1699 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1700 t
= DECL_TEMPLATE_RESULT (t
);
1702 /* Save the exceptions, in case t is a specialization and we are
1703 emitting an error about incompatible specifications. */
1704 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1706 /* Likewise for the constexpr specifier, in case t is a specialization. */
1707 constexpr_p
= (DECL_DECLARED_CONSTEXPR_P (t
)
1708 && !decl_implicit_constexpr_p (t
));
1710 /* Pretty print template instantiations only. */
1711 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1712 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1713 && flag_pretty_templates
)
1717 template_args
= DECL_TI_ARGS (t
);
1718 tmpl
= most_general_template (t
);
1719 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1721 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1726 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1727 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1729 fntype
= TREE_TYPE (t
);
1730 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1732 if (DECL_CLASS_SCOPE_P (t
))
1733 cname
= DECL_CONTEXT (t
);
1734 /* This is for partially instantiated template methods. */
1735 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1736 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1738 if (flags
& TFF_DECL_SPECIFIERS
)
1740 if (DECL_STATIC_FUNCTION_P (t
))
1741 pp_cxx_ws_string (pp
, "static");
1742 else if (DECL_VIRTUAL_P (t
))
1743 pp_cxx_ws_string (pp
, "virtual");
1747 if (DECL_DECLARED_CONCEPT_P (t
))
1748 pp_cxx_ws_string (pp
, "concept");
1749 else if (DECL_IMMEDIATE_FUNCTION_P (t
))
1750 pp_cxx_ws_string (pp
, "consteval");
1752 pp_cxx_ws_string (pp
, "constexpr");
1756 /* Print the return type? */
1758 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1759 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1762 ret
= fndecl_declared_return_type (t
);
1763 dump_type_prefix (pp
, ret
, flags
);
1766 /* Print the function name. */
1767 if (!do_outer_scope
)
1771 dump_type (pp
, cname
, flags
);
1772 pp_cxx_colon_colon (pp
);
1775 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1777 /* Name lookup for the rest of the function declarator is implicitly in the
1778 scope of the function, so avoid printing redundant scope qualifiers. */
1779 auto cds
= make_temp_override (current_dump_scope
, CP_DECL_CONTEXT (t
));
1781 dump_function_name (pp
, t
, dump_function_name_flags
);
1783 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1785 dump_parameters (pp
, parmtypes
, flags
);
1787 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1789 pp
->padding
= pp_before
;
1790 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1791 dump_ref_qualifier (pp
, fntype
, flags
);
1794 if (tx_safe_fn_type_p (fntype
))
1796 pp
->padding
= pp_before
;
1797 pp_cxx_ws_string (pp
, "transaction_safe");
1800 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1802 pp
->padding
= pp_before
;
1803 dump_exception_spec (pp
, exceptions
, flags
);
1807 dump_type_suffix (pp
, ret
, flags
);
1808 else if (deduction_guide_p (t
))
1810 pp_cxx_ws_string (pp
, "->");
1811 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1815 if (tree ci
= get_constraints (t
))
1816 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1817 pp_cxx_requires_clause (pp
, reqs
);
1819 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1821 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1823 pp_cxx_ws_string (pp
, "[inherited from");
1824 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1825 pp_character (pp
, ']');
1828 else if (template_args
)
1830 bool need_comma
= false;
1832 pp_cxx_begin_template_argument_list (pp
);
1833 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1834 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1836 tree arg
= TREE_VEC_ELT (template_args
, i
);
1838 pp_separate_with_comma (pp
);
1839 if (ARGUMENT_PACK_P (arg
))
1840 pp_cxx_left_brace (pp
);
1841 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1842 if (ARGUMENT_PACK_P (arg
))
1843 pp_cxx_right_brace (pp
);
1846 pp_cxx_end_template_argument_list (pp
);
1850 /* Print a parameter list. If this is for a member function, the
1851 member object ptr (and any other hidden args) should have
1852 already been removed. */
1855 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1858 flags
&= ~TFF_SCOPE
;
1859 pp_cxx_left_paren (pp
);
1861 for (first
= 1; parmtypes
!= void_list_node
;
1862 parmtypes
= TREE_CHAIN (parmtypes
))
1865 pp_separate_with_comma (pp
);
1869 pp_cxx_ws_string (pp
, "...");
1873 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1875 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1877 pp_cxx_whitespace (pp
);
1879 pp_cxx_whitespace (pp
);
1880 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1884 pp_cxx_right_paren (pp
);
1887 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1890 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1892 if (FUNCTION_REF_QUALIFIED (t
))
1894 pp
->padding
= pp_before
;
1895 if (FUNCTION_RVALUE_QUALIFIED (t
))
1896 pp_cxx_ws_string (pp
, "&&");
1898 pp_cxx_ws_string (pp
, "&");
1902 /* Print an exception specification. T is the exception specification. */
1905 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1907 if (t
&& TREE_PURPOSE (t
))
1909 pp_cxx_ws_string (pp
, "noexcept");
1910 if (!integer_onep (TREE_PURPOSE (t
)))
1912 pp_cxx_whitespace (pp
);
1913 pp_cxx_left_paren (pp
);
1914 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1915 pp_cxx_ws_string (pp
, "<uninstantiated>");
1917 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1918 pp_cxx_right_paren (pp
);
1923 pp_cxx_ws_string (pp
, "throw");
1924 pp_cxx_whitespace (pp
);
1925 pp_cxx_left_paren (pp
);
1926 if (TREE_VALUE (t
) != NULL_TREE
)
1929 dump_type (pp
, TREE_VALUE (t
), flags
);
1933 pp_separate_with_comma (pp
);
1935 pp_cxx_right_paren (pp
);
1939 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1940 and destructors properly. */
1943 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1945 tree name
= DECL_NAME (t
);
1947 /* We can get here with a decl that was synthesized by language-
1948 independent machinery (e.g. coverage.cc) in which case it won't
1949 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1950 will crash. In this case it is safe just to print out the
1952 if (!DECL_LANG_SPECIFIC (t
))
1954 pp_cxx_tree_identifier (pp
, name
);
1958 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1959 t
= DECL_TEMPLATE_RESULT (t
);
1961 /* Don't let the user see __comp_ctor et al. */
1962 if (DECL_CONSTRUCTOR_P (t
)
1963 || DECL_DESTRUCTOR_P (t
))
1965 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1966 name
= get_identifier ("<lambda>");
1967 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1968 name
= get_identifier ("<constructor>");
1970 name
= constructor_name (DECL_CONTEXT (t
));
1973 if (DECL_DESTRUCTOR_P (t
))
1975 pp_cxx_complement (pp
);
1976 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1978 else if (DECL_CONV_FN_P (t
))
1980 /* This cannot use the hack that the operator's return
1981 type is stashed off of its name because it may be
1982 used for error reporting. In the case of conflicting
1983 declarations, both will have the same name, yet
1984 the types will be different, hence the TREE_TYPE field
1985 of the first name will be clobbered by the second. */
1986 pp_cxx_ws_string (pp
, "operator");
1987 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1990 dump_decl (pp
, name
, flags
);
1992 dump_module_suffix (pp
, t
);
1994 if (DECL_TEMPLATE_INFO (t
)
1995 && !(flags
& TFF_TEMPLATE_NAME
)
1996 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1997 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1998 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1999 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
2003 /* Dump the template parameters from the template info INFO under control of
2004 FLAGS. PRIMARY indicates whether this is a primary template decl, or
2005 specialization (partial or complete). For partial specializations we show
2006 the specialized parameter values. For a primary template we show no
2010 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
2011 int primary
, int flags
)
2013 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
2015 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
2017 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
2018 pp_cxx_begin_template_argument_list (pp
);
2020 /* Be careful only to print things when we have them, so as not
2021 to crash producing error messages. */
2022 if (args
&& !primary
)
2025 len
= get_non_default_template_args_count (args
, flags
);
2027 args
= INNERMOST_TEMPLATE_ARGS (args
);
2028 for (ix
= 0; ix
!= len
; ix
++)
2030 tree arg
= TREE_VEC_ELT (args
, ix
);
2032 /* Only print a comma if we know there is an argument coming. In
2033 the case of an empty template argument pack, no actual
2034 argument will be printed. */
2036 && (!ARGUMENT_PACK_P (arg
)
2037 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
2038 pp_separate_with_comma (pp
);
2041 pp_string (pp
, M_("<template parameter error>"));
2043 dump_template_argument (pp
, arg
, flags
);
2048 tree tpl
= TI_TEMPLATE (info
);
2049 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
2052 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
2053 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
2055 for (ix
= 0; ix
!= len
; ix
++)
2059 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
2061 pp_string (pp
, M_("<template parameter error>"));
2065 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
2068 pp_separate_with_comma (pp
);
2070 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
2073 pp_cxx_end_template_argument_list (pp
);
2076 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
2077 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
2080 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
2083 call_expr_arg_iterator iter
;
2085 pp_cxx_left_paren (pp
);
2086 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
2092 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2093 if (more_call_expr_args_p (&iter
))
2094 pp_separate_with_comma (pp
);
2097 pp_cxx_right_paren (pp
);
2100 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
2101 using flags FLAGS. Skip over the first argument if SKIPFIRST is
2105 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2109 aggr_init_expr_arg_iterator iter
;
2111 pp_cxx_left_paren (pp
);
2112 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2118 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2119 if (more_aggr_init_expr_args_p (&iter
))
2120 pp_separate_with_comma (pp
);
2123 pp_cxx_right_paren (pp
);
2126 /* Print out a list of initializers (subr of dump_expr). */
2129 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2133 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2136 pp_separate_with_comma (pp
);
2140 /* Print out a vector of initializers (subr of dump_expr). */
2143 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2146 unsigned HOST_WIDE_INT idx
;
2149 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2151 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2152 if (idx
!= v
->length () - 1)
2153 pp_separate_with_comma (pp
);
2158 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2159 function. Resolve it to a close relative -- in the sense of static
2160 type -- variant being overridden. That is close to what was written in
2161 the source code. Subroutine of dump_expr. */
2164 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2166 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref
));
2167 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2168 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2171 fun
= TREE_CHAIN (fun
);
2172 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2173 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2179 /* Print out an expression E under control of FLAGS. */
2182 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2189 if (STATEMENT_CLASS_P (t
))
2191 pp_cxx_ws_string (pp
, M_("<statement>"));
2195 switch (TREE_CODE (t
))
2203 case NAMESPACE_DECL
:
2209 case IDENTIFIER_NODE
:
2210 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2211 |TFF_TEMPLATE_HEADER
))
2212 | TFF_NO_TEMPLATE_BINDINGS
2213 | TFF_NO_FUNCTION_ARGUMENTS
));
2217 if (SSA_NAME_VAR (t
)
2218 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2219 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2221 pp_cxx_ws_string (pp
, M_("<unknown>"));
2232 case USERDEF_LITERAL
:
2233 pp_cxx_userdef_literal (pp
, t
);
2237 /* While waiting for caret diagnostics, avoid printing
2238 __cxa_allocate_exception, __cxa_throw, and the like. */
2239 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2244 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2245 pp_cxx_colon_colon (pp
);
2246 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2250 pp_cxx_left_paren (pp
);
2251 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2252 pp_separate_with_comma (pp
);
2253 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2254 pp_cxx_right_paren (pp
);
2259 pp_cxx_left_paren (pp
);
2260 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2261 pp_string (pp
, " ? ");
2262 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2263 pp_string (pp
, " : ");
2264 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2265 pp_cxx_right_paren (pp
);
2269 if (TREE_HAS_CONSTRUCTOR (t
))
2271 pp_cxx_ws_string (pp
, "new");
2272 pp_cxx_whitespace (pp
);
2273 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2276 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2279 case AGGR_INIT_EXPR
:
2281 tree fn
= NULL_TREE
;
2283 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2284 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2286 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2288 if (DECL_CONSTRUCTOR_P (fn
))
2289 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2291 dump_decl (pp
, fn
, 0);
2294 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2296 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2301 tree fn
= CALL_EXPR_FN (t
);
2302 bool skipfirst
= false;
2304 /* Deal with internal functions. */
2305 if (fn
== NULL_TREE
)
2307 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2308 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2312 if (TREE_CODE (fn
) == ADDR_EXPR
)
2313 fn
= TREE_OPERAND (fn
, 0);
2315 /* Nobody is interested in seeing the guts of vcalls. */
2316 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2317 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2319 if (TREE_TYPE (fn
) != NULL_TREE
2320 && NEXT_CODE (fn
) == METHOD_TYPE
2321 && call_expr_nargs (t
))
2323 tree ob
= CALL_EXPR_ARG (t
, 0);
2324 if (TREE_CODE (ob
) == ADDR_EXPR
)
2326 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2327 flags
| TFF_EXPR_IN_PARENS
);
2330 else if (!is_this_parameter (ob
))
2332 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2337 if (flag_sanitize
& SANITIZE_UNDEFINED
2338 && is_ubsan_builtin_p (fn
))
2340 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2343 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2344 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2349 /* Note that this only works for G++ target exprs. If somebody
2350 builds a general TARGET_EXPR, there's no way to represent that
2351 it initializes anything other that the parameter slot for the
2352 default argument. Note we may have cleared out the first
2353 operand in expand_expr, so don't go killing ourselves. */
2354 if (TREE_OPERAND (t
, 1))
2355 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2358 case POINTER_PLUS_EXPR
:
2359 dump_binary_op (pp
, "+", t
, flags
);
2362 case POINTER_DIFF_EXPR
:
2363 dump_binary_op (pp
, "-", t
, flags
);
2368 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2374 case TRUNC_DIV_EXPR
:
2375 case TRUNC_MOD_EXPR
:
2383 case TRUTH_ANDIF_EXPR
:
2384 case TRUTH_ORIF_EXPR
:
2391 case SPACESHIP_EXPR
:
2392 case EXACT_DIV_EXPR
:
2393 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2397 case FLOOR_DIV_EXPR
:
2398 case ROUND_DIV_EXPR
:
2400 dump_binary_op (pp
, "/", t
, flags
);
2404 case FLOOR_MOD_EXPR
:
2405 case ROUND_MOD_EXPR
:
2406 dump_binary_op (pp
, "%", t
, flags
);
2411 tree ob
= TREE_OPERAND (t
, 0);
2412 if (INDIRECT_REF_P (ob
))
2414 ob
= TREE_OPERAND (ob
, 0);
2415 if (!is_this_parameter (ob
)
2416 && !is_dummy_object (ob
))
2418 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2419 if (TYPE_REF_P (TREE_TYPE (ob
)))
2427 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2428 if (TREE_CODE (ob
) != ARROW_EXPR
)
2431 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2436 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2437 pp_cxx_left_bracket (pp
);
2438 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2439 pp_cxx_right_bracket (pp
);
2442 case UNARY_PLUS_EXPR
:
2443 dump_unary_op (pp
, "+", t
, flags
);
2447 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2448 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2449 /* An ADDR_EXPR can have reference type. In that case, we
2450 shouldn't print the `&' doing so indicates to the user
2451 that the expression has pointer type. */
2453 && TYPE_REF_P (TREE_TYPE (t
))))
2454 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2455 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2456 dump_unary_op (pp
, "&&", t
, flags
);
2458 dump_unary_op (pp
, "&", t
, flags
);
2462 if (TREE_HAS_CONSTRUCTOR (t
))
2464 t
= TREE_OPERAND (t
, 0);
2465 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2466 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2467 dump_call_expr_args (pp
, t
, flags
, true);
2471 if (TREE_OPERAND (t
,0) != NULL_TREE
2472 && TREE_TYPE (TREE_OPERAND (t
, 0))
2473 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2474 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2476 dump_unary_op (pp
, "*", t
, flags
);
2481 /* Delegate to the base "C" pretty printer. */
2482 pp
->c_pretty_printer::unary_expression (t
);
2485 case TARGET_MEM_REF
:
2486 /* TARGET_MEM_REF can't appear directly from source, but can appear
2487 during late GIMPLE optimizations and through late diagnostic we might
2488 need to support it. Print it as dereferencing of a pointer after
2489 cast to the TARGET_MEM_REF type, with pointer arithmetics on some
2490 pointer to single byte types, so
2491 *(type *)((char *) ptr + step * index + index2) if all the operands
2492 are present and the casts are needed. */
2494 pp_cxx_left_paren (pp
);
2495 if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))) == NULL_TREE
2496 || !integer_onep (TYPE_SIZE_UNIT
2497 (TREE_TYPE (TREE_TYPE (TMR_BASE (t
))))))
2499 if (TYPE_SIZE_UNIT (TREE_TYPE (t
))
2500 && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t
))))
2502 pp_cxx_left_paren (pp
);
2503 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2507 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2508 pp_cxx_right_paren (pp
);
2509 pp_cxx_left_paren (pp
);
2510 pp_cxx_left_paren (pp
);
2511 dump_type (pp
, build_pointer_type (char_type_node
), flags
);
2513 pp_cxx_right_paren (pp
);
2515 else if (!same_type_p (TREE_TYPE (t
),
2516 TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))))
2518 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2519 pp_cxx_right_paren (pp
);
2520 pp_cxx_left_paren (pp
);
2522 dump_expr (pp
, TMR_BASE (t
), flags
);
2523 if (TMR_STEP (t
) && TMR_INDEX (t
))
2525 pp_cxx_ws_string (pp
, "+");
2526 dump_expr (pp
, TMR_INDEX (t
), flags
);
2527 pp_cxx_ws_string (pp
, "*");
2528 dump_expr (pp
, TMR_STEP (t
), flags
);
2532 pp_cxx_ws_string (pp
, "+");
2533 dump_expr (pp
, TMR_INDEX2 (t
), flags
);
2535 if (!integer_zerop (TMR_OFFSET (t
)))
2537 pp_cxx_ws_string (pp
, "+");
2538 dump_expr (pp
, fold_convert (ssizetype
, TMR_OFFSET (t
)), flags
);
2540 pp_cxx_right_paren (pp
);
2545 case TRUTH_NOT_EXPR
:
2546 case PREDECREMENT_EXPR
:
2547 case PREINCREMENT_EXPR
:
2548 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2551 case POSTDECREMENT_EXPR
:
2552 case POSTINCREMENT_EXPR
:
2553 pp_cxx_left_paren (pp
);
2554 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2555 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2556 pp_cxx_right_paren (pp
);
2559 case NON_LVALUE_EXPR
:
2560 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2561 should be another level of INDIRECT_REF so that I don't have to do
2563 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2565 tree next
= TREE_TYPE (TREE_TYPE (t
));
2567 while (TYPE_PTR_P (next
))
2568 next
= TREE_TYPE (next
);
2570 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2572 if (flags
& TFF_EXPR_IN_PARENS
)
2573 pp_cxx_left_paren (pp
);
2575 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2576 if (flags
& TFF_EXPR_IN_PARENS
)
2577 pp_cxx_right_paren (pp
);
2580 /* Else fall through. */
2582 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2586 case IMPLICIT_CONV_EXPR
:
2587 case VIEW_CONVERT_EXPR
:
2589 tree op
= TREE_OPERAND (t
, 0);
2591 if (location_wrapper_p (t
))
2593 dump_expr (pp
, op
, flags
);
2597 tree ttype
= TREE_TYPE (t
);
2598 tree optype
= TREE_TYPE (op
);
2600 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2601 && INDIRECT_TYPE_P (ttype
)
2602 && INDIRECT_TYPE_P (optype
)
2603 && same_type_p (TREE_TYPE (optype
),
2606 if (TYPE_REF_P (ttype
))
2609 if (TREE_CODE (op
) == ADDR_EXPR
)
2610 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2612 dump_unary_op (pp
, "*", t
, flags
);
2615 dump_unary_op (pp
, "&", t
, flags
);
2617 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2619 /* It is a cast, but we cannot tell whether it is a
2620 reinterpret or static cast. Use the C style notation. */
2621 if (flags
& TFF_EXPR_IN_PARENS
)
2622 pp_cxx_left_paren (pp
);
2623 pp_cxx_left_paren (pp
);
2624 dump_type (pp
, TREE_TYPE (t
), flags
);
2625 pp_cxx_right_paren (pp
);
2626 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2627 if (flags
& TFF_EXPR_IN_PARENS
)
2628 pp_cxx_right_paren (pp
);
2631 dump_expr (pp
, op
, flags
);
2636 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2638 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2640 if (integer_zerop (idx
))
2642 /* A NULL pointer-to-member constant. */
2643 pp_cxx_left_paren (pp
);
2644 pp_cxx_left_paren (pp
);
2645 dump_type (pp
, TREE_TYPE (t
), flags
);
2646 pp_cxx_right_paren (pp
);
2647 pp_character (pp
, '0');
2648 pp_cxx_right_paren (pp
);
2651 else if (tree_fits_shwi_p (idx
))
2654 unsigned HOST_WIDE_INT n
;
2656 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2657 t
= TYPE_METHOD_BASETYPE (t
);
2658 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2660 n
= tree_to_shwi (idx
);
2662 /* Map vtable index back one, to allow for the null pointer to
2666 while (n
> 0 && virtuals
)
2669 virtuals
= TREE_CHAIN (virtuals
);
2673 dump_expr (pp
, BV_FN (virtuals
),
2674 flags
| TFF_EXPR_IN_PARENS
);
2679 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2680 pp_string (pp
, "<lambda closure object>");
2681 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2683 dump_type (pp
, TREE_TYPE (t
), 0);
2684 pp_cxx_left_paren (pp
);
2685 pp_cxx_right_paren (pp
);
2689 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2690 dump_type (pp
, TREE_TYPE (t
), 0);
2691 pp_cxx_left_brace (pp
);
2692 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2693 pp_cxx_right_brace (pp
);
2700 tree ob
= TREE_OPERAND (t
, 0);
2701 if (is_dummy_object (ob
))
2703 t
= TREE_OPERAND (t
, 1);
2704 if (TREE_CODE (t
) == FUNCTION_DECL
)
2706 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2707 else if (BASELINK_P (t
))
2708 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2709 flags
| TFF_EXPR_IN_PARENS
);
2711 dump_decl (pp
, t
, flags
);
2715 if (INDIRECT_REF_P (ob
))
2717 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2723 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2727 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2732 case TEMPLATE_PARM_INDEX
:
2733 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2737 if (TREE_OPERAND (t
, 0) == NULL_TREE
2738 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2740 dump_type (pp
, TREE_TYPE (t
), flags
);
2741 pp_cxx_left_paren (pp
);
2742 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2743 pp_cxx_right_paren (pp
);
2747 pp_cxx_left_paren (pp
);
2748 dump_type (pp
, TREE_TYPE (t
), flags
);
2749 pp_cxx_right_paren (pp
);
2750 pp_cxx_left_paren (pp
);
2751 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2752 pp_cxx_right_paren (pp
);
2756 case STATIC_CAST_EXPR
:
2757 pp_cxx_ws_string (pp
, "static_cast");
2759 case REINTERPRET_CAST_EXPR
:
2760 pp_cxx_ws_string (pp
, "reinterpret_cast");
2762 case CONST_CAST_EXPR
:
2763 pp_cxx_ws_string (pp
, "const_cast");
2765 case DYNAMIC_CAST_EXPR
:
2766 pp_cxx_ws_string (pp
, "dynamic_cast");
2768 pp_cxx_begin_template_argument_list (pp
);
2769 dump_type (pp
, TREE_TYPE (t
), flags
);
2770 pp_cxx_end_template_argument_list (pp
);
2771 pp_cxx_left_paren (pp
);
2772 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2773 pp_cxx_right_paren (pp
);
2777 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2783 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2784 pp_cxx_ws_string (pp
, "sizeof");
2787 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2788 pp_cxx_ws_string (pp
, "__alignof__");
2790 op
= TREE_OPERAND (t
, 0);
2791 if (PACK_EXPANSION_P (op
))
2793 pp_string (pp
, "...");
2794 op
= PACK_EXPANSION_PATTERN (op
);
2796 pp_cxx_whitespace (pp
);
2797 pp_cxx_left_paren (pp
);
2798 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2799 dump_type (pp
, TREE_TYPE (op
), flags
);
2800 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2801 dump_type (pp
, op
, flags
);
2803 dump_expr (pp
, op
, flags
);
2804 pp_cxx_right_paren (pp
);
2807 case AT_ENCODE_EXPR
:
2808 pp_cxx_ws_string (pp
, "@encode");
2809 pp_cxx_whitespace (pp
);
2810 pp_cxx_left_paren (pp
);
2811 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2812 pp_cxx_right_paren (pp
);
2816 pp_cxx_ws_string (pp
, "noexcept");
2817 pp_cxx_whitespace (pp
);
2818 pp_cxx_left_paren (pp
);
2819 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2820 pp_cxx_right_paren (pp
);
2825 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2826 pp_cxx_whitespace (pp
);
2827 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2830 case DEFERRED_PARSE
:
2831 pp_string (pp
, M_("<unparsed>"));
2834 case TRY_CATCH_EXPR
:
2835 case CLEANUP_POINT_EXPR
:
2836 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2839 case PSEUDO_DTOR_EXPR
:
2840 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2842 if (TREE_OPERAND (t
, 1))
2844 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2845 pp_cxx_colon_colon (pp
);
2847 pp_cxx_complement (pp
);
2848 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2851 case TEMPLATE_ID_EXPR
:
2852 dump_decl (pp
, t
, flags
);
2858 case STATEMENT_LIST
:
2859 /* We don't yet have a way of dumping statements in a
2860 human-readable format. */
2861 pp_string (pp
, "({...})");
2865 pp_string (pp
, "while (1) { ");
2866 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2867 pp_cxx_right_brace (pp
);
2871 pp_string (pp
, "if (");
2872 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2873 pp_string (pp
, ") break; ");
2877 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2880 case EMPTY_CLASS_EXPR
:
2881 dump_type (pp
, TREE_TYPE (t
), flags
);
2882 pp_cxx_left_paren (pp
);
2883 pp_cxx_right_paren (pp
);
2886 case NON_DEPENDENT_EXPR
:
2887 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2890 case ARGUMENT_PACK_SELECT
:
2891 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2905 pp_type_specifier_seq (pp
, t
);
2909 /* We get here when we want to print a dependent type as an
2910 id-expression, without any disambiguator decoration. */
2911 pp
->id_expression (t
);
2914 case TEMPLATE_TYPE_PARM
:
2915 case TEMPLATE_TEMPLATE_PARM
:
2916 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2917 dump_type (pp
, t
, flags
);
2921 pp_cxx_trait_expression (pp
, t
);
2925 pp_cxx_va_arg_expression (pp
, t
);
2929 pp_cxx_offsetof_expression (pp
, t
);
2932 case ADDRESSOF_EXPR
:
2933 pp_cxx_addressof_expression (pp
, t
);
2937 dump_decl (pp
, t
, flags
);
2940 case EXPR_PACK_EXPANSION
:
2941 case UNARY_LEFT_FOLD_EXPR
:
2942 case UNARY_RIGHT_FOLD_EXPR
:
2943 case BINARY_LEFT_FOLD_EXPR
:
2944 case BINARY_RIGHT_FOLD_EXPR
:
2951 case VEC_DELETE_EXPR
:
2958 case UNORDERED_EXPR
:
2968 case FIX_TRUNC_EXPR
:
2973 case TRUTH_AND_EXPR
:
2975 case TRUTH_XOR_EXPR
:
2976 if (flags
& TFF_EXPR_IN_PARENS
)
2977 pp_cxx_left_paren (pp
);
2979 if (flags
& TFF_EXPR_IN_PARENS
)
2980 pp_cxx_right_paren (pp
);
2984 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2988 pp_string (pp
, M_("<lambda>"));
2992 pp_cxx_left_paren (pp
);
2993 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2994 pp_cxx_right_paren (pp
);
2998 pp_cxx_requires_expr (cxx_pp
, t
);
3002 pp_cxx_simple_requirement (cxx_pp
, t
);
3006 pp_cxx_type_requirement (cxx_pp
, t
);
3010 pp_cxx_compound_requirement (cxx_pp
, t
);
3014 pp_cxx_nested_requirement (cxx_pp
, t
);
3022 pp_cxx_constraint (cxx_pp
, t
);
3026 case PLACEHOLDER_EXPR
:
3027 pp_string (pp
, M_("*this"));
3031 dump_expr_list (pp
, t
, flags
);
3034 /* This list is incomplete, but should suffice for now.
3035 It is very important that `sorry' does not call
3036 `report_error_function'. That could cause an infinite loop. */
3038 pp_unsupported_tree (pp
, t
);
3041 pp_string (pp
, M_("<expression error>"));
3047 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
3050 pp_cxx_left_paren (pp
);
3051 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
3052 pp_cxx_whitespace (pp
);
3054 pp_cxx_ws_string (pp
, opstring
);
3056 pp_string (pp
, M_("<unknown operator>"));
3057 pp_cxx_whitespace (pp
);
3058 tree op1
= TREE_OPERAND (t
, 1);
3059 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
3060 && TREE_CODE (op1
) == INTEGER_CST
3061 && tree_int_cst_sign_bit (op1
))
3062 /* A pointer minus an integer is represented internally as plus a very
3063 large number, don't expose that to users. */
3064 op1
= convert (ssizetype
, op1
);
3065 dump_expr (pp
, op1
, flags
| TFF_EXPR_IN_PARENS
);
3066 pp_cxx_right_paren (pp
);
3070 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
3072 if (flags
& TFF_EXPR_IN_PARENS
)
3073 pp_cxx_left_paren (pp
);
3074 pp_cxx_ws_string (pp
, opstring
);
3075 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
3076 if (flags
& TFF_EXPR_IN_PARENS
)
3077 pp_cxx_right_paren (pp
);
3081 reinit_cxx_pp (void)
3083 pp_clear_output_area (cxx_pp
);
3084 cxx_pp
->padding
= pp_none
;
3085 pp_indentation (cxx_pp
) = 0;
3086 pp_needs_newline (cxx_pp
) = false;
3087 cxx_pp
->enclosing_scope
= current_function_decl
;
3090 /* Same as pp_formatted_text, except the return string is a separate
3091 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3094 pp_ggc_formatted_text (pretty_printer
*pp
)
3096 return ggc_strdup (pp_formatted_text (pp
));
3099 /* Exported interface to stringifying types, exprs and decls under TFF_*
3103 type_as_string (tree typ
, int flags
)
3106 pp_translate_identifiers (cxx_pp
) = false;
3107 dump_type (cxx_pp
, typ
, flags
);
3108 return pp_ggc_formatted_text (cxx_pp
);
3112 type_as_string_translate (tree typ
, int flags
)
3115 dump_type (cxx_pp
, typ
, flags
);
3116 return pp_ggc_formatted_text (cxx_pp
);
3120 expr_as_string (tree decl
, int flags
)
3123 pp_translate_identifiers (cxx_pp
) = false;
3124 dump_expr (cxx_pp
, decl
, flags
);
3125 return pp_ggc_formatted_text (cxx_pp
);
3128 /* Wrap decl_as_string with options appropriate for dwarf. */
3131 decl_as_dwarf_string (tree decl
, int flags
)
3134 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3135 here will be adequate to get the desired behavior. */
3136 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3137 name
= decl_as_string (decl
, flags
);
3138 /* Subsequent calls to the pretty printer shouldn't use this style. */
3139 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3144 decl_as_string (tree decl
, int flags
)
3147 pp_translate_identifiers (cxx_pp
) = false;
3148 dump_decl (cxx_pp
, decl
, flags
);
3149 return pp_ggc_formatted_text (cxx_pp
);
3153 decl_as_string_translate (tree decl
, int flags
)
3156 dump_decl (cxx_pp
, decl
, flags
);
3157 return pp_ggc_formatted_text (cxx_pp
);
3160 /* Wrap lang_decl_name with options appropriate for dwarf. */
3163 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3166 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3167 here will be adequate to get the desired behavior. */
3168 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3169 name
= lang_decl_name (decl
, v
, translate
);
3170 /* Subsequent calls to the pretty printer shouldn't use this style. */
3171 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3175 /* Generate the three forms of printable names for cxx_printable_name. */
3178 lang_decl_name (tree decl
, int v
, bool translate
)
3182 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3183 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3186 pp_translate_identifiers (cxx_pp
) = translate
;
3188 && (DECL_CLASS_SCOPE_P (decl
)
3189 || (DECL_NAMESPACE_SCOPE_P (decl
)
3190 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3192 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3193 pp_cxx_colon_colon (cxx_pp
);
3196 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3197 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3198 else if ((DECL_NAME (decl
) == NULL_TREE
)
3199 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3200 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3202 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3204 return pp_ggc_formatted_text (cxx_pp
);
3207 /* Return the location of a tree passed to %+ formats. */
3210 location_of (tree t
)
3214 t
= TYPE_MAIN_DECL (t
);
3216 return input_location
;
3218 else if (TREE_CODE (t
) == OVERLOAD
)
3222 return DECL_SOURCE_LOCATION (t
);
3223 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3224 return defparse_location (t
);
3225 return cp_expr_loc_or_input_loc (t
);
3228 /* Now the interfaces from error et al to dump_type et al. Each takes an
3229 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3233 decl_to_string (tree decl
, int verbose
)
3237 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3238 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3239 flags
= TFF_CLASS_KEY_OR_ENUM
;
3241 flags
|= TFF_DECL_SPECIFIERS
;
3242 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3243 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3244 flags
|= TFF_TEMPLATE_HEADER
;
3247 dump_decl (cxx_pp
, decl
, flags
);
3248 return pp_ggc_formatted_text (cxx_pp
);
3252 expr_to_string (tree decl
)
3255 dump_expr (cxx_pp
, decl
, 0);
3256 return pp_ggc_formatted_text (cxx_pp
);
3260 fndecl_to_string (tree fndecl
, int verbose
)
3264 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3265 | TFF_TEMPLATE_HEADER
;
3267 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3269 dump_decl (cxx_pp
, fndecl
, flags
);
3270 return pp_ggc_formatted_text (cxx_pp
);
3275 code_to_string (enum tree_code c
)
3277 return get_tree_code_name (c
);
3281 language_to_string (enum languages c
)
3288 case lang_cplusplus
:
3297 /* Return the proper printed version of a parameter to a C++ function. */
3300 parm_to_string (int p
)
3304 pp_string (cxx_pp
, "'this'");
3306 pp_decimal_int (cxx_pp
, p
+ 1);
3307 return pp_ggc_formatted_text (cxx_pp
);
3311 op_to_string (bool assop
, enum tree_code p
)
3313 tree id
= ovl_op_identifier (assop
, p
);
3314 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3317 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3319 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3320 string in appropriate places, and *QUOTE is written to with false
3321 to suppress pp_format's trailing close quote so that e.g.
3322 foo_typedef {aka underlying_foo} {enum}
3323 can be printed by "%qT" as:
3324 `foo_typedef' {aka `underlying_foo'} {enum}
3326 `foo_typedef {aka underlying_foo} {enum}'
3327 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3328 then a leading open quote will be added, whereas if POSTPROCESSED is false
3329 (for handling %T) then any leading quote has already been added by
3330 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3333 SHOW_COLOR is used to determine the colorization of any quotes that
3337 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3342 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3343 flags
|= TFF_TEMPLATE_HEADER
;
3347 if (postprocessed
&& quote
&& *quote
)
3348 pp_begin_quote (cxx_pp
, show_color
);
3350 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3351 int type_start
, type_len
;
3352 type_start
= obstack_object_size (ob
);
3354 dump_type (cxx_pp
, typ
, flags
);
3356 /* Remember the end of the initial dump. */
3357 type_len
= obstack_object_size (ob
) - type_start
;
3359 /* If we're printing a type that involves typedefs, also print the
3360 stripped version. But sometimes the stripped version looks
3361 exactly the same, so we don't want it after all. To avoid printing
3362 it in that case, we play ugly obstack games. */
3363 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3364 && !uses_template_parms (typ
))
3366 int aka_start
, aka_len
; char *p
;
3367 tree aka
= strip_typedefs (typ
, NULL
, STF_USER_VISIBLE
);
3368 if (quote
&& *quote
)
3369 pp_end_quote (cxx_pp
, show_color
);
3370 pp_string (cxx_pp
, " {aka");
3371 pp_cxx_whitespace (cxx_pp
);
3372 if (quote
&& *quote
)
3373 pp_begin_quote (cxx_pp
, show_color
);
3374 /* And remember the start of the aka dump. */
3375 aka_start
= obstack_object_size (ob
);
3376 dump_type (cxx_pp
, aka
, flags
);
3377 aka_len
= obstack_object_size (ob
) - aka_start
;
3378 if (quote
&& *quote
)
3379 pp_end_quote (cxx_pp
, show_color
);
3380 pp_right_brace (cxx_pp
);
3381 p
= (char*)obstack_base (ob
);
3382 /* If they are identical, cut off the aka by unwinding the obstack. */
3383 if (type_len
== aka_len
3384 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3386 /* We can't add a '\0' here, since we may be adding a closing quote
3387 below, and it would be hidden by the '\0'.
3388 Instead, manually unwind the current object within the obstack
3389 so that the insertion point is at the end of the type, before
3391 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3392 gcc_assert (delta
<= 0);
3393 obstack_blank_fast (ob
, delta
);
3397 /* No further closing quotes are needed. */
3401 if (quote
&& *quote
)
3403 pp_end_quote (cxx_pp
, show_color
);
3406 return pp_ggc_formatted_text (cxx_pp
);
3410 args_to_string (tree p
, int verbose
)
3414 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3419 if (TYPE_P (TREE_VALUE (p
)))
3420 return type_as_string_translate (p
, flags
);
3423 for (; p
; p
= TREE_CHAIN (p
))
3425 if (null_node_p (TREE_VALUE (p
)))
3426 pp_cxx_ws_string (cxx_pp
, "NULL");
3428 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3430 pp_separate_with_comma (cxx_pp
);
3432 return pp_ggc_formatted_text (cxx_pp
);
3435 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3436 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3440 subst_to_string (tree p
)
3442 tree decl
= TREE_PURPOSE (p
);
3443 tree targs
= TREE_VALUE (p
);
3444 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3445 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3446 |TFF_NO_TEMPLATE_BINDINGS
);
3452 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3453 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3454 return pp_ggc_formatted_text (cxx_pp
);
3458 cv_to_string (tree p
, int v
)
3461 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3462 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3463 return pp_ggc_formatted_text (cxx_pp
);
3467 eh_spec_to_string (tree p
, int /*v*/)
3471 dump_exception_spec (cxx_pp
, p
, flags
);
3472 return pp_ggc_formatted_text (cxx_pp
);
3475 /* Langhook for print_error_function. */
3477 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3478 diagnostic_info
*diagnostic
)
3482 prefix
= xstrdup (file
);
3485 lhd_print_error_function (context
, file
, diagnostic
);
3486 pp_set_prefix (context
->printer
, prefix
);
3487 maybe_print_instantiation_context (context
);
3491 cp_diagnostic_starter (diagnostic_context
*context
,
3492 diagnostic_info
*diagnostic
)
3494 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3495 cp_print_error_function (context
, diagnostic
);
3496 maybe_print_instantiation_context (context
);
3497 maybe_print_constexpr_context (context
);
3498 maybe_print_constraint_context (context
);
3499 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3503 /* Print current function onto BUFFER, in the process of reporting
3504 a diagnostic message. Called from cp_diagnostic_starter. */
3506 cp_print_error_function (diagnostic_context
*context
,
3507 diagnostic_info
*diagnostic
)
3509 /* If we are in an instantiation context, current_function_decl is likely
3510 to be wrong, so just rely on print_instantiation_full_context. */
3511 if (current_instantiation ())
3513 /* The above is true for constraint satisfaction also. */
3514 if (current_failed_constraint
)
3516 if (diagnostic_last_function_changed (context
, diagnostic
))
3518 char *old_prefix
= pp_take_prefix (context
->printer
);
3519 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3520 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3521 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3522 ? file_name_as_prefix (context
, file
) : NULL
;
3524 pp_set_prefix (context
->printer
, new_prefix
);
3526 if (current_function_decl
== NULL
)
3527 pp_string (context
->printer
, _("At global scope:"));
3532 if (abstract_origin
)
3534 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3535 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3539 fndecl
= current_function_decl
;
3541 pp_printf (context
->printer
, function_category (fndecl
),
3542 cxx_printable_name_translate (fndecl
, 2));
3544 while (abstract_origin
)
3547 tree block
= abstract_origin
;
3549 locus
= &BLOCK_SOURCE_LOCATION (block
);
3551 block
= BLOCK_SUPERCONTEXT (block
);
3552 while (block
&& TREE_CODE (block
) == BLOCK
3553 && BLOCK_ABSTRACT_ORIGIN (block
))
3555 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3556 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3561 else if (TREE_CODE (ao
) != BLOCK
)
3564 block
= BLOCK_SUPERCONTEXT (block
);
3567 abstract_origin
= block
;
3570 while (block
&& TREE_CODE (block
) == BLOCK
)
3571 block
= BLOCK_SUPERCONTEXT (block
);
3573 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3575 abstract_origin
= NULL
;
3579 expanded_location s
= expand_location (*locus
);
3580 pp_character (context
->printer
, ',');
3581 pp_newline (context
->printer
);
3584 if (context
->show_column
&& s
.column
!= 0)
3585 pp_printf (context
->printer
,
3586 _(" inlined from %qs at %r%s:%d:%d%R"),
3587 cxx_printable_name_translate (fndecl
, 2),
3588 "locus", s
.file
, s
.line
, s
.column
);
3590 pp_printf (context
->printer
,
3591 _(" inlined from %qs at %r%s:%d%R"),
3592 cxx_printable_name_translate (fndecl
, 2),
3593 "locus", s
.file
, s
.line
);
3597 pp_printf (context
->printer
, _(" inlined from %qs"),
3598 cxx_printable_name_translate (fndecl
, 2));
3601 pp_character (context
->printer
, ':');
3603 pp_newline (context
->printer
);
3605 diagnostic_set_last_function (context
, diagnostic
);
3606 pp_destroy_prefix (context
->printer
);
3607 context
->printer
->prefix
= old_prefix
;
3611 /* Returns a description of FUNCTION using standard terminology. The
3612 result is a format string of the form "In CATEGORY %qs". */
3614 function_category (tree fn
)
3616 /* We can get called from the middle-end for diagnostics of function
3617 clones. Make sure we have language specific information before
3618 dereferencing it. */
3619 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3620 && DECL_FUNCTION_MEMBER_P (fn
))
3622 if (DECL_STATIC_FUNCTION_P (fn
))
3623 return _("In static member function %qs");
3624 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3625 return _("In copy constructor %qs");
3626 else if (DECL_CONSTRUCTOR_P (fn
))
3627 return _("In constructor %qs");
3628 else if (DECL_DESTRUCTOR_P (fn
))
3629 return _("In destructor %qs");
3630 else if (LAMBDA_FUNCTION_P (fn
))
3631 return _("In lambda function");
3633 return _("In member function %qs");
3636 return _("In function %qs");
3639 /* Disable warnings about missing quoting in GCC diagnostics for
3640 the pp_verbatim calls. Their format strings deliberately don't
3641 follow GCC diagnostic conventions. */
3643 #pragma GCC diagnostic push
3644 #pragma GCC diagnostic ignored "-Wformat-diag"
3647 /* Report the full context of a current template instantiation,
3650 print_instantiation_full_context (diagnostic_context
*context
)
3652 struct tinst_level
*p
= current_instantiation ();
3653 location_t location
= input_location
;
3657 pp_verbatim (context
->printer
,
3659 ? _("%s: In substitution of %qS:\n")
3660 : _("%s: In instantiation of %q#D:\n"),
3661 LOCATION_FILE (location
),
3664 location
= p
->locus
;
3668 print_instantiation_partial_context (context
, p
, location
);
3671 /* Helper function of print_instantiation_partial_context() that
3672 prints a single line of instantiation context. */
3675 print_instantiation_partial_context_line (diagnostic_context
*context
,
3676 struct tinst_level
*t
,
3677 location_t loc
, bool recursive_p
)
3679 if (loc
== UNKNOWN_LOCATION
)
3682 expanded_location xloc
= expand_location (loc
);
3684 if (context
->show_column
)
3685 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3686 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3688 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3689 "locus", xloc
.file
, xloc
.line
);
3694 pp_verbatim (context
->printer
,
3696 ? _("recursively required by substitution of %qS\n")
3697 : _("required by substitution of %qS\n"),
3700 pp_verbatim (context
->printer
,
3702 ? _("recursively required from %q#D\n")
3703 : _("required from %q#D\n"),
3708 pp_verbatim (context
->printer
,
3710 ? _("recursively required from here\n")
3711 : _("required from here\n"));
3715 /* Same as print_instantiation_full_context but less verbose. */
3718 print_instantiation_partial_context (diagnostic_context
*context
,
3719 struct tinst_level
*t0
, location_t loc
)
3721 struct tinst_level
*t
;
3724 location_t prev_loc
= loc
;
3726 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3727 if (prev_loc
!= t
->locus
)
3729 prev_loc
= t
->locus
;
3735 if (template_backtrace_limit
3736 && n_total
> template_backtrace_limit
)
3738 int skip
= n_total
- template_backtrace_limit
;
3739 int head
= template_backtrace_limit
/ 2;
3741 /* Avoid skipping just 1. If so, skip 2. */
3745 head
= (template_backtrace_limit
- 1) / 2;
3748 for (n
= 0; n
< head
; n
++)
3750 gcc_assert (t
!= NULL
);
3751 if (loc
!= t
->locus
)
3752 print_instantiation_partial_context_line (context
, t
, loc
,
3753 /*recursive_p=*/false);
3757 if (t
!= NULL
&& skip
> 0)
3759 expanded_location xloc
;
3760 xloc
= expand_location (loc
);
3761 if (context
->show_column
)
3762 pp_verbatim (context
->printer
,
3763 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3764 "contexts, use -ftemplate-backtrace-limit=0 to "
3766 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3768 pp_verbatim (context
->printer
,
3769 _("%r%s:%d:%R [ skipping %d instantiation "
3770 "contexts, use -ftemplate-backtrace-limit=0 to "
3772 "locus", xloc
.file
, xloc
.line
, skip
);
3777 } while (t
!= NULL
&& --skip
> 0);
3783 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3788 print_instantiation_partial_context_line (context
, t
, loc
,
3793 print_instantiation_partial_context_line (context
, NULL
, loc
,
3794 /*recursive_p=*/false);
3797 /* Called from cp_thing to print the template context for an error. */
3799 maybe_print_instantiation_context (diagnostic_context
*context
)
3801 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3804 record_last_problematic_instantiation ();
3805 print_instantiation_full_context (context
);
3808 /* Report what constexpr call(s) we're trying to expand, if any. */
3811 maybe_print_constexpr_context (diagnostic_context
*context
)
3813 vec
<tree
> call_stack
= cx_error_context ();
3817 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3819 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3820 const char *s
= expr_as_string (t
, 0);
3821 if (context
->show_column
)
3822 pp_verbatim (context
->printer
,
3823 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3824 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3826 pp_verbatim (context
->printer
,
3827 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3828 "locus", xloc
.file
, xloc
.line
, s
);
3829 pp_newline (context
->printer
);
3835 print_location (diagnostic_context
*context
, location_t loc
)
3837 expanded_location xloc
= expand_location (loc
);
3838 if (context
->show_column
)
3839 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3840 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3842 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3843 "locus", xloc
.file
, xloc
.line
);
3847 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3849 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3850 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3854 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3856 gcc_assert (concept_check_p (expr
));
3858 tree id
= unpack_concept_check (expr
);
3859 tree tmpl
= TREE_OPERAND (id
, 0);
3861 tmpl
= OVL_FIRST (tmpl
);
3863 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3865 cxx_pretty_printer
*pp
= (cxx_pretty_printer
*)context
->printer
;
3866 pp_verbatim (pp
, "required for the satisfaction of %qE", expr
);
3867 if (map
&& map
!= error_mark_node
)
3869 tree subst_map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3870 pp_cxx_parameter_mapping (pp
, (subst_map
!= error_mark_node
3871 ? subst_map
: map
));
3876 /* Diagnose the entry point into the satisfaction error. Returns the next
3880 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3882 tree src
= TREE_VALUE (cxt
);
3885 print_location (context
, input_location
);
3886 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3891 print_constrained_decl_info (context
, src
);
3896 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3897 return TREE_CHAIN (cxt
);
3902 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3905 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3906 tree map
= ATOMIC_CONSTR_MAP (constr
);
3907 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3908 if (map
== error_mark_node
)
3911 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3912 pp_verbatim (context
->printer
, "in requirements ");
3914 tree parms
= TREE_OPERAND (expr
, 0);
3916 pp_verbatim (context
->printer
, "with ");
3919 pp_verbatim (context
->printer
, "%q#D", parms
);
3920 if (TREE_CHAIN (parms
))
3921 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
3922 parms
= TREE_CHAIN (parms
);
3924 pp_cxx_parameter_mapping ((cxx_pretty_printer
*)context
->printer
, map
);
3926 pp_verbatim (context
->printer
, "\n");
3930 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
3935 tree constr
= TREE_VALUE (failed
);
3936 if (!constr
|| constr
== error_mark_node
)
3938 tree cxt
= CONSTR_CONTEXT (constr
);
3941 tree args
= TREE_PURPOSE (failed
);
3943 /* Print the stack of requirements. */
3944 cxt
= print_constraint_context_head (context
, cxt
, args
);
3945 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
3947 tree expr
= TREE_VALUE (cxt
);
3948 tree map
= TREE_PURPOSE (cxt
);
3949 print_concept_check_info (context
, expr
, map
, args
);
3950 cxt
= TREE_CHAIN (cxt
);
3953 /* For certain constraints, we can provide additional context. */
3954 if (TREE_CODE (constr
) == ATOMIC_CONSTR
3955 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
3956 print_requires_expression_info (context
, constr
, args
);
3960 maybe_print_constraint_context (diagnostic_context
*context
)
3962 if (!current_failed_constraint
)
3965 tree cur
= current_failed_constraint
;
3967 /* Recursively print nested contexts. */
3968 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
3969 if (current_failed_constraint
)
3970 maybe_print_constraint_context (context
);
3972 /* Print this context. */
3973 maybe_print_single_constraint_context (context
, cur
);
3976 /* Return true iff TYPE_A and TYPE_B are template types that are
3977 meaningful to compare. */
3980 comparable_template_types_p (tree type_a
, tree type_b
)
3982 if (!CLASS_TYPE_P (type_a
))
3984 if (!CLASS_TYPE_P (type_b
))
3987 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3988 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3989 if (!tinfo_a
|| !tinfo_b
)
3992 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3995 /* Start a new line indented by SPC spaces on PP. */
3998 newline_and_indent (pretty_printer
*pp
, int spc
)
4001 for (int i
= 0; i
< spc
; i
++)
4005 /* Generate a GC-allocated string for ARG, an expression or type. */
4008 arg_to_string (tree arg
, bool verbose
)
4011 return type_to_string (arg
, verbose
, true, NULL
, false);
4013 return expr_to_string (arg
);
4016 /* Subroutine to type_to_string_with_compare and
4017 print_template_tree_comparison.
4019 Print a representation of ARG (an expression or type) to PP,
4020 colorizing it as "type-diff" if PP->show_color. */
4023 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
4025 pp_printf (pp
, "%r%s%R",
4028 ? arg_to_string (arg
, verbose
)
4029 : G_("(no argument)")));
4032 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
4034 The types must satisfy comparable_template_types_p.
4036 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
4037 potentially colorizing/eliding in comparison with TYPE_B.
4039 For example given types:
4040 vector<map<int,double>>
4042 vector<map<int,float>>
4043 then the result on PP would be:
4044 vector<map<[...],double>>
4045 with type elision, and:
4046 vector<map<int,double>>
4047 without type elision.
4049 In both cases the parts of TYPE that differ from PEER will be colorized
4050 if pp_show_color (pp) is true. In the above example, this would be
4053 If INDENT is non-zero, then the types are printed in a tree-like form
4054 which shows both types. In the above example, the result on PP would be:
4061 and without type-elision would be:
4068 As before, the differing parts of the types are colorized if
4069 pp_show_color (pp) is true ("double" and "float" in this example).
4071 Template arguments in which both types are using the default arguments
4072 are not printed; if at least one of the two types is using a non-default
4073 argument, then that argument is printed (or both arguments for the
4074 tree-like print format). */
4077 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
4078 bool verbose
, int indent
)
4081 newline_and_indent (pp
, indent
);
4083 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
4084 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
4086 pp_printf (pp
, "%s<",
4087 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
4089 tree args_a
= TI_ARGS (tinfo_a
);
4090 tree args_b
= TI_ARGS (tinfo_b
);
4091 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4092 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4094 int len_a
= get_non_default_template_args_count (args_a
, flags
);
4095 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
4096 int len_b
= get_non_default_template_args_count (args_b
, flags
);
4097 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
4098 /* Determine the maximum range of args for which non-default template args
4099 were used; beyond this, only default args (if any) were used, and so
4100 they will be equal from this point onwards.
4101 One of the two peers might have used default arguments within this
4102 range, but the other will be using non-default arguments, and so
4103 it's more readable to print both within this range, to highlight
4105 int len_max
= MAX (len_a
, len_b
);
4106 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4107 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4108 for (int idx
= 0; idx
< len_max
; idx
++)
4111 pp_character (pp
, ',');
4113 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
4114 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
4118 newline_and_indent (pp
, indent
+ 2);
4119 /* Can do elision here, printing "[...]". */
4120 if (flag_elide_type
)
4121 pp_string (pp
, G_("[...]"));
4123 pp_string (pp
, arg_to_string (arg_a
, verbose
));
4127 int new_indent
= indent
? indent
+ 2 : 0;
4128 if (comparable_template_types_p (arg_a
, arg_b
))
4129 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
4133 newline_and_indent (pp
, indent
+ 2);
4134 pp_character (pp
, '[');
4135 print_nonequal_arg (pp
, arg_a
, verbose
);
4136 pp_string (pp
, " != ");
4137 print_nonequal_arg (pp
, arg_b
, verbose
);
4138 pp_character (pp
, ']');
4141 print_nonequal_arg (pp
, arg_a
, verbose
);
4144 pp_printf (pp
, ">");
4147 /* As type_to_string, but for a template, potentially colorizing/eliding
4148 in comparison with PEER.
4149 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4150 then the resulting string would be:
4152 with type elision, and:
4154 without type elision.
4156 In both cases the parts of TYPE that differ from PEER will be colorized
4157 if SHOW_COLOR is true. In the above example, this would be "double".
4159 Template arguments in which both types are using the default arguments
4160 are not printed; if at least one of the two types is using a non-default
4161 argument, then both arguments are printed.
4163 The resulting string is in a GC-allocated buffer. */
4166 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4169 pretty_printer inner_pp
;
4170 pretty_printer
*pp
= &inner_pp
;
4171 pp_show_color (pp
) = show_color
;
4173 print_template_differences (pp
, type
, peer
, verbose
, 0);
4174 return pp_ggc_formatted_text (pp
);
4177 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4178 indented by INDENT spaces.
4180 For example given types:
4182 vector<map<int,double>>
4186 vector<map<double,float>>
4188 the output with type elision would be:
4195 and without type-elision would be:
4202 TYPE_A and TYPE_B must both be comparable template types
4203 (as per comparable_template_types_p).
4205 Template arguments in which both types are using the default arguments
4206 are not printed; if at least one of the two types is using a non-default
4207 argument, then both arguments are printed. */
4210 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4211 bool verbose
, int indent
)
4213 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4216 /* Subroutine for use in a format_postprocessor::handle
4217 implementation. Adds a chunk to the end of
4218 formatted output, so that it will be printed
4219 by pp_output_formatted_text. */
4222 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4224 output_buffer
*buffer
= pp_buffer (pp
);
4225 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4226 const char **args
= chunk_array
->args
;
4228 unsigned int chunk_idx
;
4229 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4231 args
[chunk_idx
++] = content
;
4232 args
[chunk_idx
] = NULL
;
4235 /* Create a copy of CONTENT, with quotes added, and,
4236 potentially, with colorization.
4237 No escaped is performed on CONTENT.
4238 The result is in a GC-allocated buffer. */
4241 add_quotes (const char *content
, bool show_color
)
4243 pretty_printer tmp_pp
;
4244 pp_show_color (&tmp_pp
) = show_color
;
4246 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4247 quoting colorization bytes within the results and using either
4248 pp_quote or pp_begin_quote doesn't work the same. */
4249 pp_printf (&tmp_pp
, "%<%s%>", content
);
4251 return pp_ggc_formatted_text (&tmp_pp
);
4255 #pragma GCC diagnostic pop
4258 /* If we had %H and %I, and hence deferred printing them,
4259 print them now, storing the result into the chunk_info
4260 for pp_format. Quote them if 'q' was provided.
4261 Also print the difference in tree form, adding it as
4262 an additional chunk. */
4265 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4267 /* If we have one of %H and %I, the other should have
4269 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4271 /* Avoid reentrancy issues by working with a copy of
4272 m_type_a and m_type_b, resetting them now. */
4273 deferred_printed_type type_a
= m_type_a
;
4274 deferred_printed_type type_b
= m_type_b
;
4275 m_type_a
= deferred_printed_type ();
4276 m_type_b
= deferred_printed_type ();
4278 gcc_assert (type_a
.m_buffer_ptr
);
4279 gcc_assert (type_b
.m_buffer_ptr
);
4281 bool show_color
= pp_show_color (pp
);
4283 const char *type_a_text
;
4284 const char *type_b_text
;
4286 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4289 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4290 type_a
.m_verbose
, show_color
);
4292 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4293 type_b
.m_verbose
, show_color
);
4295 if (flag_diagnostics_show_template_tree
)
4297 pretty_printer inner_pp
;
4298 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4299 print_template_tree_comparison
4300 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4301 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4306 /* If the types were not comparable (or if only one of %H/%I was
4307 provided), they are printed normally, and no difference tree
4309 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4310 true, &type_a
.m_quote
, show_color
);
4311 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4312 true, &type_b
.m_quote
, show_color
);
4316 type_a_text
= add_quotes (type_a_text
, show_color
);
4317 *type_a
.m_buffer_ptr
= type_a_text
;
4320 type_b_text
= add_quotes (type_b_text
, show_color
);
4321 *type_b
.m_buffer_ptr
= type_b_text
;
4325 /* Subroutine for handling %H and %I, to support i18n of messages like:
4327 error_at (loc, "could not convert %qE from %qH to %qI",
4328 expr, type_a, type_b);
4330 so that we can print things like:
4332 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4334 and, with type-elision:
4336 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4338 (with color-coding of the differences between the types).
4340 The %H and %I format codes are peers: both must be present,
4341 and they affect each other. Hence to handle them, we must
4342 delay printing until we have both, deferring the printing to
4343 pretty_printer's m_format_postprocessor hook.
4345 This is called in phase 2 of pp_format, when it is accumulating
4346 a series of formatted chunks. We stash the location of the chunk
4347 we're meant to have written to, so that we can write to it in the
4348 m_format_postprocessor hook.
4350 We also need to stash whether a 'q' prefix was provided (the QUOTE
4351 param) so that we can add the quotes when writing out the delayed
4355 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4356 tree type
, const char **buffer_ptr
,
4357 bool verbose
, bool quote
)
4359 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4360 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4361 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4365 /* Called from output_format -- during diagnostic message processing --
4366 to handle C++ specific format specifier with the following meanings:
4367 %A function argument-list.
4371 %F function declaration.
4372 %H type difference (from).
4373 %I type difference (to).
4374 %L language as used in extern "lang".
4376 %P function parameter whose position is indicated by an integer.
4377 %Q assignment operator.
4378 %S substitution (template + args)
4381 %X exception-specification. */
4383 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4384 int precision
, bool wide
, bool set_locus
, bool verbose
,
4385 bool *quoted
, const char **buffer_ptr
)
4387 gcc_assert (pp
->m_format_postprocessor
);
4388 cxx_format_postprocessor
*postprocessor
4389 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4393 #define next_tree (t = va_arg (*text->args_ptr, tree))
4394 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4395 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4396 #define next_int va_arg (*text->args_ptr, int)
4398 if (precision
!= 0 || wide
)
4403 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4404 case 'C': result
= code_to_string (next_tcode
); break;
4407 tree temp
= next_tree
;
4409 && DECL_HAS_DEBUG_EXPR_P (temp
))
4411 temp
= DECL_DEBUG_EXPR (temp
);
4414 result
= expr_to_string (temp
);
4418 result
= decl_to_string (temp
, verbose
);
4421 case 'E': result
= expr_to_string (next_tree
); break;
4422 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4424 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4425 buffer_ptr
, verbose
, *quoted
);
4428 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4429 buffer_ptr
, verbose
, *quoted
);
4431 case 'L': result
= language_to_string (next_lang
); break;
4432 case 'O': result
= op_to_string (false, next_tcode
); break;
4433 case 'P': result
= parm_to_string (next_int
); break;
4434 case 'Q': result
= op_to_string (true, next_tcode
); break;
4435 case 'S': result
= subst_to_string (next_tree
); break;
4438 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4439 pp_show_color (pp
));
4442 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4443 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4449 pp_string (pp
, result
);
4450 if (set_locus
&& t
!= NULL
)
4451 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4459 /* Warn about the use of C++0x features when appropriate. */
4461 maybe_warn_cpp0x (cpp0x_warn_str str
, location_t loc
/*=input_location*/)
4463 if (cxx_dialect
== cxx98
)
4466 case CPP0X_INITIALIZER_LISTS
:
4467 pedwarn (loc
, OPT_Wc__11_extensions
,
4468 "extended initializer lists "
4469 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4471 case CPP0X_EXPLICIT_CONVERSION
:
4472 pedwarn (loc
, OPT_Wc__11_extensions
,
4473 "explicit conversion operators "
4474 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4476 case CPP0X_VARIADIC_TEMPLATES
:
4477 pedwarn (loc
, OPT_Wc__11_extensions
,
4478 "variadic templates "
4479 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4481 case CPP0X_LAMBDA_EXPR
:
4482 pedwarn (loc
, OPT_Wc__11_extensions
,
4483 "lambda expressions "
4484 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4487 pedwarn (loc
, OPT_Wc__11_extensions
,
4488 "C++11 auto only available with %<-std=c++11%> or "
4489 "%<-std=gnu++11%>");
4491 case CPP0X_SCOPED_ENUMS
:
4492 pedwarn (loc
, OPT_Wc__11_extensions
,
4493 "scoped enums only available with %<-std=c++11%> or "
4494 "%<-std=gnu++11%>");
4496 case CPP0X_DEFAULTED_DELETED
:
4497 pedwarn (loc
, OPT_Wc__11_extensions
,
4498 "defaulted and deleted functions "
4499 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4501 case CPP0X_INLINE_NAMESPACES
:
4503 pedwarn (loc
, OPT_Wc__11_extensions
,
4504 "inline namespaces "
4505 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4507 case CPP0X_OVERRIDE_CONTROLS
:
4508 pedwarn (loc
, OPT_Wc__11_extensions
,
4509 "override controls (override/final) "
4510 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4513 pedwarn (loc
, OPT_Wc__11_extensions
,
4514 "non-static data member initializers "
4515 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4517 case CPP0X_USER_DEFINED_LITERALS
:
4518 pedwarn (loc
, OPT_Wc__11_extensions
,
4519 "user-defined literals "
4520 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4522 case CPP0X_DELEGATING_CTORS
:
4523 pedwarn (loc
, OPT_Wc__11_extensions
,
4524 "delegating constructors "
4525 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4527 case CPP0X_INHERITING_CTORS
:
4528 pedwarn (loc
, OPT_Wc__11_extensions
,
4529 "inheriting constructors "
4530 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4532 case CPP0X_ATTRIBUTES
:
4533 pedwarn (loc
, OPT_Wc__11_extensions
,
4535 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4537 case CPP0X_REF_QUALIFIER
:
4538 pedwarn (loc
, OPT_Wc__11_extensions
,
4540 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4547 /* Warn about the use of variadic templates when appropriate. */
4549 maybe_warn_variadic_templates (void)
4551 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4555 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4556 option OPT with text GMSGID. Use this function to report
4557 diagnostics for constructs that are invalid C++98, but valid
4560 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4562 diagnostic_info diagnostic
;
4565 rich_location
richloc (line_table
, location
);
4567 va_start (ap
, gmsgid
);
4568 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4569 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4570 diagnostic
.option_index
= opt
;
4571 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4576 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4577 we found when we tried to do the lookup. LOCATION is the location of
4578 the NAME identifier. */
4581 qualified_name_lookup_error (tree scope
, tree name
,
4582 tree decl
, location_t location
)
4584 if (scope
== error_mark_node
)
4585 ; /* We already complained. */
4586 else if (TYPE_P (scope
))
4588 if (!COMPLETE_TYPE_P (scope
))
4589 error_at (location
, "incomplete type %qT used in nested name specifier",
4591 else if (TREE_CODE (decl
) == TREE_LIST
)
4593 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4595 print_candidates (decl
);
4600 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4601 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4602 if (const char *suggestion
= hint
.suggestion ())
4604 gcc_rich_location
richloc (location
);
4605 richloc
.add_fixit_replace (suggestion
);
4607 "%qD is not a member of %qT; did you mean %qs?",
4608 name
, scope
, suggestion
);
4611 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4614 else if (scope
!= global_namespace
)
4616 auto_diagnostic_group d
;
4617 bool emit_fixit
= true;
4619 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4622 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4623 /* "location" is just the location of the name, not of the explicit
4624 scope, and it's not easy to get at the latter, so we can't issue
4625 fix-it hints for the suggestion. */
4628 if (const char *suggestion
= hint
.suggestion ())
4630 gcc_rich_location
richloc (location
);
4632 richloc
.add_fixit_replace (suggestion
);
4633 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4634 name
, scope
, suggestion
);
4637 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4641 auto_diagnostic_group d
;
4642 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4643 if (const char *suggestion
= hint
.suggestion ())
4645 gcc_rich_location
richloc (location
);
4646 richloc
.add_fixit_replace (suggestion
);
4648 "%<::%D%> has not been declared; did you mean %qs?",
4652 error_at (location
, "%<::%D%> has not been declared", name
);
4656 /* C++-specific implementation of range_label::get_text () vfunc for
4657 range_label_for_type_mismatch.
4659 Compare with print_template_differences above. */
4662 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4664 if (m_labelled_type
== NULL_TREE
)
4665 return label_text::borrow (NULL
);
4667 const bool verbose
= false;
4668 const bool show_color
= false;
4672 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4673 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4674 verbose
, show_color
);
4676 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4678 /* Both of the above return GC-allocated buffers, so the caller mustn't
4680 return label_text::borrow (result
);