diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3f894fedd8d57acb1055cb87327534c7556d67b2..65c9c2c540c5b57a1420c62bc1c788fee316e85d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-24  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	PR c++/50828
+	* error.c (dump_function_decl): Strip TFF_TEMPLATE_NAME from flags
+	at the outset.
+
 2012-09-24  Jason Merrill  <jason@redhat.com>
 
 	* decl.c (get_atexit_node): Remove dead code.
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 30fa0182a8f468664270f08b8217957f6035dba6..c8b614b165c95a82a38e62b27ca0c132e6d43ede 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1348,7 +1348,7 @@ dump_function_decl (tree t, int flags)
       return;
     }
 
-  flags &= ~TFF_UNQUALIFIED_NAME;
+  flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME);
   if (TREE_CODE (t) == TEMPLATE_DECL)
     t = DECL_TEMPLATE_RESULT (t);