Patchwork C++ PATCH for c++/49221 (ICE with decltype of ->*)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 6, 2011, 4:30 a.m.
Message ID <4E3CC375.1010800@redhat.com>
Download mbox | patch
Permalink /patch/108758/
State New
Headers show

Comments

Jason Merrill - Aug. 6, 2011, 4:30 a.m.
5.5 says, "If the result of .* or ->* is a function, then that result 
can be used only as the operand for the function call
operator ()."  We need to enforce that in finish_decltype_type.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

Patch

commit b5a38c10b1755e85d931c05b9b5f85b348d0eb94
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 5 17:45:14 2011 -0400

    	PR c++/49921
    	* semantics.c (finish_decltype_type): Call invalid_nonstatic_memfn_p.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 2f02e69..3d836eb 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -4948,6 +4948,9 @@  finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
       return error_mark_node;
     }
 
+  if (invalid_nonstatic_memfn_p (expr, complain))
+    return error_mark_node;
+
   /* To get the size of a static data member declared as an array of
      unknown bound, we need to instantiate it.  */
   if (TREE_CODE (expr) == VAR_DECL
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype31.C b/gcc/testsuite/g++.dg/cpp0x/decltype31.C
new file mode 100644
index 0000000..b9817eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype31.C
@@ -0,0 +1,13 @@ 
+// PR c++/49921
+// { dg-options -std=c++0x }
+
+struct Local
+{
+  void f();
+};
+
+Local *l;
+void (Local::*ptr)();
+decltype((l->*ptr)) i;	       // { dg-error "member function" }
+
+// { dg-prune-output "invalid type in declaration" }