On 05/04/2017 07:44 PM, David Malcolm wrote:
This patch kit implements two new options to make it easier
to read diagnostics involving mismatched template types:
-fdiagnostics-show-template-tree and
-fno-elide-type.
It adds two new formatting codes: %H and %I which are
equivalent to %qT, but are to be used together for type
comparisons e.g.
"can't convert from %H to %I".
While I can see why one might want %H and %I to imply quoting, it seems
confusingly inconsistent with the other formatters, which require an
explicit 'q'.
rather than printing:
could not convert 'std::map<int, std::vector<double> >()'
from 'std::map<int, std::vector<double> >' to 'std::map<int,
std::vector<float> >'
with -felide-type (the default), it prints:
could not convert 'std::map<int, std::vector<double> >()'
from 'map<[...],vector<double>>' to 'map<[...],vector<float>>
Neat.
Is '-felide-type' a good name? Wouldn't something like
'-fdiagnostic-elide-template-args' be better?
With -fdiagnostics-show-template-tree a tree-like structure of the
template is printed, showing the differences; in this case:
'tree' sounds implementor-speaky, Perhaps
'-fdiagnostic-expand-template-args' or something?
Right, bikeshedding out of the way ...
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -99,7 +99,47 @@ static void cp_diagnostic_starter (diagnostic_context *,
diagnostic_info *);
static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
+
+/* Return true iff TYPE_A and TYPE_B are template types that are
+ meaningful to compare. */
+
+static bool
+comparable_template_types_p (tree type_a, tree type_b)
+{
+ if (TREE_CODE (type_a) != RECORD_TYPE)
+ return false;
+ if (TREE_CODE (type_b) != RECORD_TYPE)
+ return false;
CLASS_TYPE_P (type_a) etc?
+ int len_max = MAX (len_a, len_b);
+ for (int idx = 0; idx < len_max; idx++)
+ {
+ tree arg_a = idx < len_a ? TREE_VEC_ELT (args_a, idx) : NULL;
+ tree arg_b = idx < len_b ? TREE_VEC_ELT (args_b, idx) : NULL;
+ if (arg_a == arg_b)
Should this use same_type_p for types? If direct comparison is correct,
a comment would help.
+ Only non-default template arguments are printed. */
+
+static void
+print_template_tree_comparison (pretty_printer *pp, tree type_a, tree type_b,
+ for (int idx = 0; idx < len_max; idx++)
+ {
+ tree arg_a = idx < len_a ? TREE_VEC_ELT (args_a, idx) : NULL;
+ tree arg_b = idx < len_b ? TREE_VEC_ELT (args_b, idx) : NULL;
+ if (arg_a == arg_b)
Same question. If these have to be comparable template type, when can
len_a and len_b be different?
+ This is called in phase 2 of pp_format, when it is accumulating
+ a series of formatted chunks. We stash the location of the chunk
+ we're meant to have written to, so that we can write to it in the
+ m_format_postprocessor hook. */
+
+static void
+defer_half_of_type_diff (pretty_printer *pp, char spec, tree type,
If this is called 'phase 2' why not name the function for that, rather
than 'half'?
+ case 'H':
+ case 'I':
+ {
+ defer_half_of_type_diff (pp, *spec, next_tree, buffer_ptr, verbose);
Why not tell defer_half_of_type_diff whether it's doing the %H bit or
the %I bit directly, rather than have it also check for H and I?
I've not looked more than cursorily at the non C++ bits.
nathan
--
Nathan Sidwell