]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/25185 (deep typedef substitution in error message)
authorJason Merrill <jason@redhat.com>
Tue, 7 Apr 2009 17:48:52 +0000 (13:48 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 7 Apr 2009 17:48:52 +0000 (13:48 -0400)
PR c++/25185
* c-common.h, c-common.c: Add flag_pretty_templates.
* c-opts.c (c_common_handle_option): Set it.
* c.opt: Add -fno-pretty-templates.
* doc/invoke.texi (C++ Dialect Options): Likewise.

* error.c (dump_function_decl): Don't pretty-print templates
if -fno-pretty-templates.
(count_non_default_template_args): Print all args if
-fno-pretty-templates.

From-SVN: r145697

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-opts.c
gcc/c.opt
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/error40.C [new file with mode: 0644]

index e52e732b9af386b8f4fe7606745f7d177965a49a..6f448917444d41e2cfee2ed949f00631b0e10c02 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-07  Jason Merrill  <jason@redhat.com>
+
+       PR c++/25185
+       * c-common.h, c-common.c: Add flag_pretty_templates.
+       * c-opts.c (c_common_handle_option): Set it.
+       * c.opt: Add -fno-pretty-templates.
+       * doc/invoke.texi (C++ Dialect Options): Likewise.
+
 2009-04-07  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/ia64/ia64.c (ia64_builtins): Add IA64_BUILTIN_HUGE_VALQ.
index 9886cdf36689f07bdd8af45ceb482a3ad5001d5d..3d114550fa253c49e4edf61e860621f594c14eec 100644 (file)
@@ -593,6 +593,11 @@ int flag_enforce_eh_specs = 1;
 
 int flag_threadsafe_statics = 1;
 
+/* Nonzero if we want to pretty-print template specializations as the
+   template signature followed by the arguments.  */
+
+int flag_pretty_templates = 1;
+
 /* Nonzero means warn about implicit declarations.  */
 
 int warn_implicit = 1;
index f5c755b22bf4fffe706fdeaebdedb56a31e703d4..0d85a936e72c821f2e24f32294fc3a4dcc76fad6 100644 (file)
@@ -695,6 +695,11 @@ extern int flag_enforce_eh_specs;
 
 extern int flag_threadsafe_statics;
 
+/* Nonzero if we want to pretty-print template specializations as the
+   template signature followed by the arguments.  */
+
+extern int flag_pretty_templates;
+
 /* Nonzero means warn about implicit declarations.  */
 
 extern int warn_implicit;
index 395399194708d3dbc2d3210f4b5eb05f2720d159..54edf302ab0bf5128d46b28ff805eb95313643ef 100644 (file)
@@ -808,6 +808,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
       flag_threadsafe_statics = value;
       break;
 
+    case OPT_fpretty_templates:
+      flag_pretty_templates = value;
+      break;
+
     case OPT_fzero_link:
       flag_zero_link = value;
       break;
index 40681bdc377732fa1f756661cc33bf735607e14b..3f1cd1301a0722a598b2cd6a477da3800af31a7f 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -716,6 +716,10 @@ fpreprocessed
 C ObjC C++ ObjC++
 Treat the input file as already preprocessed
 
+fpretty-templates
+C++ ObjC++
+-fno-pretty-templates Do not pretty-print template specializations as the template signature followed by the arguments
+
 freplace-objc-classes
 ObjC ObjC++
 Used in Fix-and-Continue mode to indicate that object files may be swapped in at runtime
index 02440e516e04b77bf9d12e67856023da00ece9dd..08daf462594ac6112331bb5808e88efe63e484fb 100644 (file)
@@ -1,3 +1,11 @@
+2009-04-07  Jason Merrill  <jason@redhat.com>
+
+       PR c++/25185
+       * error.c (dump_function_decl): Don't pretty-print templates
+       if -fno-pretty-templates.
+       (count_non_default_template_args): Print all args if
+       -fno-pretty-templates.
+
 2009-04-06  Jason Merrill  <jason@redhat.com>
 
        PR c++/35146
index a97017a9794e5ee6bc9806c4601a373cb5a30806..fc32d99b50e616d6048f0b3b1581e8c599711a6d 100644 (file)
@@ -163,7 +163,7 @@ count_non_default_template_args (tree args, tree params)
   int n = TREE_VEC_LENGTH (args);
   int last;
 
-  if (params == NULL_TREE)
+  if (params == NULL_TREE || !flag_pretty_templates)
     return n;
 
   for (last = n - 1; last >= 0; --last)
@@ -1206,7 +1206,8 @@ dump_function_decl (tree t, int flags)
   exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t));
 
   /* Pretty print template instantiations only.  */
-  if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
+  if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t)
+      && flag_pretty_templates)
     {
       tree tmpl;
 
index 5eb977673bee20fe1d6ef29257814efe39e2fbee..b5d795a104be5b168497a98de4117d5cfab10eea 100644 (file)
@@ -188,6 +188,7 @@ in the following sections.
 -fno-implement-inlines  -fms-extensions @gol
 -fno-nonansi-builtins  -fno-operator-names @gol
 -fno-optional-diags  -fpermissive @gol
+-fno-pretty-templates @gol
 -frepo  -fno-rtti  -fstats  -ftemplate-depth-@var{n} @gol
 -fno-threadsafe-statics -fuse-cxa-atexit  -fno-weak  -nostdinc++ @gol
 -fno-default-inline  -fvisibility-inlines-hidden @gol
@@ -1834,6 +1835,19 @@ Downgrade some diagnostics about nonconformant code from errors to
 warnings.  Thus, using @option{-fpermissive} will allow some
 nonconforming code to compile.
 
+@item -fno-pretty-templates
+@opindex fno-pretty-templates
+When an error message refers to a specialization of a function
+template, the compiler will normally print the signature of the
+template followed by the template arguments and any typedefs or
+typenames in the signature (e.g. @code{void f(T) [with T = int]}
+rather than @code{void f(int)}) so that it's clear which template is
+involved.  When an error message refers to a specialization of a class
+template, the compiler will omit any template arguments which match
+the default template arguments for that template.  If either of these
+behaviors make it harder to understand the error message rather than
+easier, using @option{-fno-pretty-templates} will disable them.
+
 @item -frepo
 @opindex frepo
 Enable automatic template instantiation at link time.  This option also
index 688d1b553c053d17f2ada57f316f628ae115c661..a48515af9b57a594168cb9428a1bcd2eab76391b 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-07  Jason Merrill  <jason@redhat.com>
+
+       PR c++/25185
+       * g++.dg/template/error40.C: New.
+
 2009-04-07  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/38152
diff --git a/gcc/testsuite/g++.dg/template/error40.C b/gcc/testsuite/g++.dg/template/error40.C
new file mode 100644 (file)
index 0000000..f449832
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-options "-fno-pretty-templates" }
+
+template <class T, int N=0, int X=1>
+struct A
+{
+};
+
+void foo(void)
+{
+  A<void> a = 0;               // { dg-error "A<void, 0, 1>" }
+}
+
+template <class T> T f(T);         // { dg-message "int f<int>.int." }
+template <class T> T f(T, int = 0); // { dg-message "" }
+
+int main()
+{
+  f(1);                                // { dg-error "" }
+}