Hi,

maybe this old issue is already fixed. We used to ICE on:

typedef void (*fptr)() __attribute((noreturn));
template<int> void foo();
template<fptr> void bar();

fptr f = bar< foo<0> >;

but lately we simply reject it:

34938.C:5:10: error: no matches converting function ‘bar’ to type ‘fptr {aka void (*)() volatile}’
fptr f = bar< foo<0> >;
^
34938.C:3:21: note: candidate is: template<void (* <anonymous>)() volatile> void bar()
template<fptr> void bar();
^

is that Ok? clang behaves like us, EDG accepts the code. A secondary issue I noticed is that we print 'volatile' instead of the attribute, that is fixed by the patchlet below.

Thanks,
Paolo.

//////////////////////////
Index: c/c-objc-common.c
===================================================================
--- c/c-objc-common.c   (revision 214335)
+++ c/c-objc-common.c   (working copy)
@@ -165,7 +165,8 @@ c_tree_printer (pretty_printer *pp, text_info *tex
       return true;
 
     case 'v':
-      pp_c_cv_qualifiers (cpp, va_arg (*text->args_ptr, int), hash);
+      pp_c_cv_qualifiers (cpp, va_arg (*text->args_ptr, int), hash,
+                         /*method_type*/false);
       return true;
 
     default:
Index: c-family/c-pretty-print.c
===================================================================
--- c-family/c-pretty-print.c   (revision 214335)
+++ c-family/c-pretty-print.c   (working copy)
@@ -168,7 +168,8 @@ pp_c_exclamation (c_pretty_printer *pp)
 /* Print out the external representation of QUALIFIERS.  */
 
 void
-pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
+pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers,
+                   bool func_type, bool method_type)
 {
   const char *p = pp_last_position_in_text (pp);
   bool previous = false;
@@ -192,7 +193,8 @@ void
     {
       if (previous)
         pp_c_whitespace (pp);
-      pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
+      pp_c_ws_string (pp, (func_type && !method_type
+                          ? "__attribute__((const))" : "const"));
       previous = true;
     }
 
@@ -200,7 +202,8 @@ void
     {
       if (previous)
         pp_c_whitespace (pp);
-      pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : 
"volatile");
+      pp_c_ws_string (pp, (func_type || method_type
+                          ? "__attribute__((noreturn))" : "volatile"));
       previous = true;
     }
 
@@ -273,7 +276,8 @@ pp_c_type_qualifier_list (c_pretty_printer *pp, tr
 
   qualifiers = TYPE_QUALS (t);
   pp_c_cv_qualifiers (pp, qualifiers,
-                     TREE_CODE (t) == FUNCTION_TYPE);
+                     TREE_CODE (t) == FUNCTION_TYPE,
+                     TREE_CODE (t) == METHOD_TYPE);
 
   if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
     {
Index: c-family/c-pretty-print.h
===================================================================
--- c-family/c-pretty-print.h   (revision 214335)
+++ c-family/c-pretty-print.h   (working copy)
@@ -119,7 +119,8 @@ void pp_c_tree_decl_identifier (c_pretty_printer *
 void pp_c_function_definition (c_pretty_printer *, tree);
 void pp_c_attributes (c_pretty_printer *, tree);
 void pp_c_attributes_display (c_pretty_printer *, tree);
-void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type);
+void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers,
+                        bool func_type, bool method_type);
 void pp_c_type_qualifier_list (c_pretty_printer *, tree);
 void pp_c_parameter_type_list (c_pretty_printer *, tree);
 void pp_c_specifier_qualifier_list (c_pretty_printer *, tree);
Index: cp/cxx-pretty-print.h
===================================================================
--- cp/cxx-pretty-print.h       (revision 214335)
+++ 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, MT)   \
+   pp_c_cv_qualifiers (PP, CV, FT, MT)
 
 #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 214335)
+++ cp/error.c  (working copy)
@@ -839,7 +839,9 @@ 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),
+                             TREE_CODE (t) == FUNCTION_TYPE,
+                             TREE_CODE (t) == METHOD_TYPE);
        dump_ref_qualifier (pp, t, flags);
        dump_exception_spec (pp, TYPE_RAISES_EXCEPTIONS (t), flags);
        dump_type_suffix (pp, TREE_TYPE (t), flags);

Reply via email to