[Bug c++/44783] implement -ftemplate-backtrace-limit=
manu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Feb 14 16:27:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44783
--- Comment #11 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-02-14 16:26:10 UTC ---
(In reply to comment #10)
> By the way, for the actual dejagnu testcase, a few weeks ago I noticed that
> apparently testing for 'note:' is pretty weak, like if additional notes are
> emitted (additional in the sense that there is no corresponding dg-message to
> match) that doesn't lead to failure. Did you see anything like that?
Any number of notes will be matched by a single "note:" test, since the
testsuite does not detect duplicates. There is PR about this somewhere.
> Anyway, about the code, if I understand correctly your explanation, 'n_total >
> template_backtrace_limit + 1' would lead to the exact same default behavior we
> have now, but appears to misbehave a little when template_backtrace_limit == 1
> and n_total == 2 because we really want 1 note in that case, that is what the
> user really asked, right? Then probably what you wrote in the draft is fine,
> but I don't have a strong opinion, really, I only noticed something 'weird'
> going on with that condition and decided to ask.
So I used the testcase testsuite/g++.dg/cpp0x/noexcept15.C to play a bit.
I noticed that my earlier version never prints "skipping 1 instantiation
contexts". Now I recall that this was done on purpose. It seems pointless to
print a line "skipping 1" instead of the actual instantiation context. Also, we
don't have to deal with singular/plural. ;-)
However, this means that in some cases, we would actually print one more than
the limit. If we just say that the limit is a limit not the exact number
printed, a workaround is to print one less in that case. So:
limit n_total printed skipped
5 5 5 0
5 7 5 2
5 6 4 2
I also added the option name to the message for convenience (clang also does
this if I recall correctly).
- if (n_total >= 12)
+ if (template_backtrace_limit &&
+ n_total > template_backtrace_limit)
{
- int skip = n_total - 10;
- for (n = 0; n < 5; n++)
+ int skip = n_total - template_backtrace_limit;
+ int head = template_backtrace_limit/ 2;
+ /* Avoid skipping just 1. If so, skip 2. */
+ if (skip == 1)
+ {
+ skip = 2;
+ head = (template_backtrace_limit - 1) / 2;
+ }
+
+ for (n = 0; n < head; n++)
{
gcc_assert (t != NULL);
if (loc != t->locus)
print_instantiation_partial_context_line (context, t, loc,
/*recursive_p=*/false);
loc = t->locus;
t = t->next;
}
- if (t != NULL && skip > 1)
+ if (t != NULL && skip > 0)
{
expanded_location xloc;
xloc = expand_location (loc);
if (context->show_column)
pp_verbatim (context->printer,
- _("%s:%d:%d: [ skipping %d instantiation contexts
]\n"),
+ _("%s:%d:%d: [ skipping %d instantiation contexts,
use -ftemplate-backtrace-limit=0 to disable ]\n"),
xloc.file, xloc.line, xloc.column, skip);
else
pp_verbatim (context->printer,
- _("%s:%d: [ skipping %d instantiation contexts
]\n"),
+ _("%s:%d: [ skipping %d instantiation contexts, use
-ftemplate-backtrace-limit=0 to disable ]\n"),
xloc.file, xloc.line, skip);
More information about the Gcc-bugs
mailing list