From f89b94d954b87c1b90293d14f1ca1ed15d2ee8f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Sun, 21 Feb 2010 21:20:04 +0000 Subject: [PATCH] re PR c++/23510 (skip some instantation contexts if there are too many) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2010-02-21 Manuel López-Ibáñez PR c++/23510 cp/ * error.c (print_instantiation_partial_context_line): New. (print_instantiation_partial_context): Print at most 12 contexts, skip the rest with a message. testsuite/ * g++.dg/template/recurse.C: Adjust. * g++.dg/template/pr23510.C: New. From-SVN: r156942 --- gcc/cp/ChangeLog | 7 ++ gcc/cp/error.c | 101 ++++++++++++++++++------ gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/g++.dg/template/pr23510.C | 23 ++++++ gcc/testsuite/g++.dg/template/recurse.C | 4 +- 5 files changed, 116 insertions(+), 25 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/pr23510.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2ce5e020195..e933965fec4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2010-02-21 Manuel López-Ibáñez + + PR c++/23510 + * error.c (print_instantiation_partial_context_line): New. + (print_instantiation_partial_context): Print at most 12 contexts, + skip the rest with a message. + 2010-02-21 Dodji Seketeli PR c++/42824 diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 3d9f1424685..b03c83ff152 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -2728,36 +2728,89 @@ print_instantiation_full_context (diagnostic_context *context) print_instantiation_partial_context (context, p, location); } -/* Same as above but less verbose. */ +/* Helper function of print_instantiation_partial_context() that + prints a single line of instantiation context. */ + static void -print_instantiation_partial_context (diagnostic_context *context, - struct tinst_level *t, location_t loc) +print_instantiation_partial_context_line (diagnostic_context *context, + const struct tinst_level *t, location_t loc) { expanded_location xloc; - const char *str; - for (; ; t = t->next) + xloc = expand_location (loc); + + if (t != NULL) { + const char *str; + str = decl_as_string_translate (t->decl, + TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE); + if (flag_show_column) + pp_verbatim (context->printer, + _("%s:%d:%d: instantiated from %qs\n"), + xloc.file, xloc.line, xloc.column, str); + else + pp_verbatim (context->printer, + _("%s:%d: instantiated from %qs\n"), + xloc.file, xloc.line, str); + } else { + if (flag_show_column) + pp_verbatim (context->printer, _("%s:%d:%d: instantiated from here"), + xloc.file, xloc.line, xloc.column); + else + pp_verbatim (context->printer, _("%s:%d: instantiated from here"), + xloc.file, xloc.line); + } +} + +/* Same as print_instantiation_full_context but less verbose. */ + +static void +print_instantiation_partial_context (diagnostic_context *context, + struct tinst_level *t0, location_t loc) +{ + struct tinst_level *t; + int n_total = 0; + int n; + + for (t = t0; t != NULL; t = t->next) + n_total++; + + t = t0; + + if (n_total >= 12) { - xloc = expand_location (loc); - if (t == NULL) - break; - str = decl_as_string_translate (t->decl, - TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE); - if (flag_show_column) - pp_verbatim (context->printer, - _("%s:%d:%d: instantiated from %qs\n"), - xloc.file, xloc.line, xloc.column, str); - else - pp_verbatim (context->printer, - _("%s:%d: instantiated from %qs\n"), - xloc.file, xloc.line, str); + int skip = n_total - 10; + for (n = 0; n < 5; n++) + { + gcc_assert (t != NULL); + print_instantiation_partial_context_line (context, t, loc); + loc = t->locus; + t = t->next; + } + if (skip > 1) + { + expanded_location xloc; + xloc = expand_location (loc); + if (flag_show_column) + pp_verbatim (context->printer, + _("%s:%d:%d: [ skipping %d instantiation contexts ]\n"), + xloc.file, xloc.line, xloc.column, skip); + else + pp_verbatim (context->printer, + _("%s:%d: [ skipping %d instantiation contexts ]\n"), + xloc.file, xloc.line, skip); + + do { + loc = t->locus; + t = t->next; + } while (--skip > 0); + } + } + + for (; t != NULL; t = t->next) + { + print_instantiation_partial_context_line (context, t, loc); loc = t->locus; } - if (flag_show_column) - pp_verbatim (context->printer, _("%s:%d:%d: instantiated from here"), - xloc.file, xloc.line, xloc.column); - else - pp_verbatim (context->printer, _("%s:%d: instantiated from here"), - xloc.file, xloc.line); + print_instantiation_partial_context_line (context, NULL, loc); pp_base_newline (context->printer); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc94d47287e..7db619e31be 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-02-21 Manuel López-Ibáñez + + PR c++/23510 + * g++.dg/template/recurse.C: Adjust. + * g++.dg/template/pr23510.C: New. + 2010-02-21 Dodji Seketeli PR c++/42824 diff --git a/gcc/testsuite/g++.dg/template/pr23510.C b/gcc/testsuite/g++.dg/template/pr23510.C new file mode 100644 index 00000000000..a0806e245c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr23510.C @@ -0,0 +1,23 @@ +// { dg-do compile } +// { dg-options "-ftemplate-depth-15" } +template +struct Factorial +{ + enum { nValue = nFactor * Factorial::nValue }; // { dg-error "depth exceeds maximum" } + // { dg-message "skipping 5 instantiation contexts" "" { target *-*-* } 6 } + // { dg-error "incomplete type" "" { target *-*-* } 6 } +} + + template<> // { dg-error "expected" } + struct Factorial<0> + { + enum { nValue = 1 }; + } + + static const unsigned int FACTOR = 20; + +int main() +{ + Factorial::nValue; + return 0; +} diff --git a/gcc/testsuite/g++.dg/template/recurse.C b/gcc/testsuite/g++.dg/template/recurse.C index 25552d05ef9..17fe1866eb2 100644 --- a/gcc/testsuite/g++.dg/template/recurse.C +++ b/gcc/testsuite/g++.dg/template/recurse.C @@ -6,8 +6,10 @@ template struct F int operator()() { F f; // { dg-error "incomplete type" "incomplete" } - // { dg-error "exceeds maximum" "exceeds" { target *-*-* } 8 } + // { dg-bogus "exceeds maximum.*exceeds maximum" "exceeds" { xfail *-*-* } 8 } + // { dg-error "exceeds maximum" "exceeds" { xfail *-*-* } 8 } return f()*I; // { dg-message "instantiated" "recurse" } + // { dg-message "skipping 40 instantiation contexts" "" { target *-*-* } 11 } } }; -- 2.30.2