OSDN Git Service

2010-02-21 Manuel López-Ibáñez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 21 Feb 2010 21:20:04 +0000 (21:20 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 21 Feb 2010 21:20:04 +0000 (21:20 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156942 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/pr23510.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/recurse.C

index 2ce5e02..e933965 100644 (file)
@@ -1,3 +1,10 @@
+2010-02-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       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  <dodji@redhat.com>
 
        PR c++/42824
index 3d9f142..b03c83f 100644 (file)
@@ -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);
 }
 
index cc94d47..7db619e 100644 (file)
@@ -1,3 +1,9 @@
+2010-02-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/23510
+       * g++.dg/template/recurse.C: Adjust.
+       * g++.dg/template/pr23510.C: New.
+
 2010-02-21  Dodji Seketeli  <dodji@redhat.com>
 
        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 (file)
index 0000000..a0806e2
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-do compile } 
+// { dg-options "-ftemplate-depth-15" }
+template<unsigned int nFactor>
+struct Factorial
+{
+  enum { nValue = nFactor * Factorial<nFactor - 1>::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<FACTOR>::nValue;
+  return 0;
+}
index 25552d0..17fe186 100644 (file)
@@ -6,8 +6,10 @@ template <int I> struct F
   int operator()()
     {
       F<I+1> 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 }
     }
 };