Hi again,
On 08/22/2014 09:33 PM, Paolo Carlini wrote:
Hi,
On 08/22/2014 09:27 PM, Jason Merrill wrote:
On 08/22/2014 03:19 PM, Paolo Carlini wrote:
Ok. Currently in cases like the present one, dump_type_suffix upon a
pointer recurses and we end up calling pp_cxx_cv_qualifiers on the
given
FUNCTION_TYPE / METHOD_TYPE. Thus pp_cxx_cv_qualifiers lacks the
pointer
context, just sees the latter. Do you think that the current simple
setup, thus my patch which just extends it, can be incorrect in some
cases?
Yes, I think your patch changes it to be incorrect in different cases
than the ones where it's currently incorrect, namely the typedef and
template argument cases that I mentioned.
Let me think about this. I'm not sure to understand what this boils
down to, if we have to seriously restructure what we have got or not.
Do you think that we have to track during the recursion in
dump_type_suffix that the FUNCTION_TYPE / METHOD_TYPE comes from a
pointer?
Like the below, which I'm finishing testing?
Note that apparently this regressed in 4.9, after some clean ups and C++
work to the diagnostic committed by Gaby. Thus maybe eventually we want
to fix the issue in the release branch too.
Thanks,
Paolo.
PS: Something I also noticed is that we ignore the noreturn attribute in:
typedef void (A::*ptrmf)() __attribute((noreturn));
I don't remember a Bugzilla for that, but I suppose it should be fine.
clang doesn't complain for sure. And what about references?
typedef void (&fref)() __attribute((noreturn));
/////////////////////////
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h (revision 214359)
+++ cp/cp-tree.h (working copy)
@@ -4728,7 +4728,8 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, T
TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS: do not omit template arguments
identical to their defaults.
TFF_NO_TEMPLATE_BINDINGS: do not print information about the template
- arguments for a function template specialization. */
+ arguments for a function template specialization.
+ TFF_POINTER: we are printing a pointer type. */
#define TFF_PLAIN_IDENTIFIER (0)
#define TFF_SCOPE (1)
@@ -4745,6 +4746,7 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, T
#define TFF_UNQUALIFIED_NAME (1 << 11)
#define TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS (1 << 12)
#define TFF_NO_TEMPLATE_BINDINGS (1 << 13)
+#define TFF_POINTER (1 << 14)
/* Returns the TEMPLATE_DECL associated to a TEMPLATE_TEMPLATE_PARM
node. */
Index: cp/cxx-pretty-print.h
===================================================================
--- cp/cxx-pretty-print.h (revision 214359)
+++ cp/cxx-pretty-print.h (working copy)
@@ -59,8 +59,8 @@ struct cxx_pretty_printer : c_pretty_printer
#define pp_cxx_cv_qualifier_seq(PP, T) \
pp_c_type_qualifier_list (PP, T)
-#define pp_cxx_cv_qualifiers(PP, CV) \
- pp_c_cv_qualifiers (PP, CV, false)
+#define pp_cxx_cv_qualifiers(PP, CV, FT) \
+ pp_c_cv_qualifiers (PP, CV, FT)
#define pp_cxx_whitespace(PP) pp_c_whitespace (PP)
#define pp_cxx_left_paren(PP) pp_c_left_paren (PP)
Index: cp/error.c
===================================================================
--- cp/error.c (revision 214359)
+++ cp/error.c (working copy)
@@ -820,6 +820,8 @@ dump_type_suffix (cxx_pretty_printer *pp, tree t,
if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
|| TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
pp_cxx_right_paren (pp);
+ if (TREE_CODE (t) == POINTER_TYPE)
+ flags |= TFF_POINTER;
dump_type_suffix (pp, TREE_TYPE (t), flags);
break;
@@ -839,7 +841,7 @@ dump_type_suffix (cxx_pretty_printer *pp, tree t,
dump_parameters (pp, arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
pp->padding = pp_before;
- pp_cxx_cv_qualifiers (pp, type_memfn_quals (t));
+ pp_cxx_cv_qualifiers (pp, type_memfn_quals (t), flags & TFF_POINTER);
dump_ref_qualifier (pp, t, flags);
dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags);
dump_type_suffix (pp, TREE_TYPE (t), flags);
Index: testsuite/g++.dg/template/pr34938.C
===================================================================
--- testsuite/g++.dg/template/pr34938.C (revision 0)
+++ testsuite/g++.dg/template/pr34938.C (working copy)
@@ -0,0 +1,7 @@
+// PR c++/34938
+
+typedef void (*fptr)() __attribute((noreturn));
+template<int> void foo();
+template<fptr> void bar();
+
+fptr f = bar< foo<0> >; // { dg-error "noreturn" }