From 6ea2bd47dd50fdf50e5b71e7349dae094f2920fe Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 7 Apr 2009 13:48:52 -0400 Subject: [PATCH] re PR c++/25185 (deep typedef substitution in error message) 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 | 8 ++++++++ gcc/c-common.c | 5 +++++ gcc/c-common.h | 5 +++++ gcc/c-opts.c | 4 ++++ gcc/c.opt | 4 ++++ gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/error.c | 5 +++-- gcc/doc/invoke.texi | 14 ++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/error40.C | 19 +++++++++++++++++++ 10 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/error40.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e52e732b9af..6f448917444 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2009-04-07 Jason Merrill + + 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 * config/ia64/ia64.c (ia64_builtins): Add IA64_BUILTIN_HUGE_VALQ. diff --git a/gcc/c-common.c b/gcc/c-common.c index 9886cdf3668..3d114550fa2 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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; diff --git a/gcc/c-common.h b/gcc/c-common.h index f5c755b22bf..0d85a936e72 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -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; diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 39539919470..54edf302ab0 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -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; diff --git a/gcc/c.opt b/gcc/c.opt index 40681bdc377..3f1cd1301a0 100644 --- 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 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 02440e516e0..08daf462594 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2009-04-07 Jason Merrill + + 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 PR c++/35146 diff --git a/gcc/cp/error.c b/gcc/cp/error.c index a97017a9794..fc32d99b50e 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -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; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5eb977673be..b5d795a104b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 688d1b553c0..a48515af9b5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-07 Jason Merrill + + PR c++/25185 + * g++.dg/template/error40.C: New. + 2009-04-07 Janus Weil 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 index 00000000000..f449832063f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error40.C @@ -0,0 +1,19 @@ +// { dg-options "-fno-pretty-templates" } + +template +struct A +{ +}; + +void foo(void) +{ + A a = 0; // { dg-error "A" } +} + +template T f(T); // { dg-message "int f.int." } +template T f(T, int = 0); // { dg-message "" } + +int main() +{ + f(1); // { dg-error "" } +}