public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ RFC/Patch] PR 34938
@ 2014-08-22 17:53 Paolo Carlini
  2014-08-22 18:17 ` Jason Merrill
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Carlini @ 2014-08-22 17:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

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.

//////////////////////////

[-- Attachment #2: patch_34938 --]
[-- Type: text/plain, Size: 4041 bytes --]

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);

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-08-25  2:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-22 17:53 [C++ RFC/Patch] PR 34938 Paolo Carlini
2014-08-22 18:17 ` Jason Merrill
2014-08-22 19:19   ` Paolo Carlini
2014-08-22 19:27     ` Jason Merrill
2014-08-22 19:33       ` Paolo Carlini
2014-08-22 19:48         ` Manuel López-Ibáñez
2014-08-22 19:56           ` Jason Merrill
2014-08-22 20:35         ` Paolo Carlini
2014-08-22 20:45           ` Jason Merrill
2014-08-22 21:16             ` Paolo Carlini
2014-08-23  7:16               ` Paolo Carlini
2014-08-23 15:03                 ` Paolo Carlini
2014-08-25  2:53                   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).