Patchwork C++ PATCH for c++/53788 (accepts-invalid with call to method in decltype)

login
register
mail settings
Submitter Jason Merrill
Date July 3, 2012, 3:28 a.m.
Message ID <4FF266FA.2000507@redhat.com>
Download mbox | patch
Permalink /patch/168679/
State New
Headers show

Comments

Jason Merrill - July 3, 2012, 3:28 a.m.
The diagnostic for calling a non-static member function without an 
associated object depends on the form of the dummy object built by 
build_dummy_object.  If we wrap it in a NON_DEPENDENT_EXPR, then 
is_dummy_object doesn't recognize it any more.  So don't wrap it.

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

Patch

commit 66f75d714661171ff026b8ccf3d99ce9a4d536e2
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jul 2 17:06:33 2012 -0400

    	PR c++/53788
    	* pt.c (build_non_dependent_expr): Don't wrap a dummy object.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f8f416a..563a1ad 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -20215,6 +20215,10 @@  build_non_dependent_expr (tree expr)
   if (BRACE_ENCLOSED_INITIALIZER_P (expr))
     return expr;
 
+  /* Don't wrap a dummy object, we need to be able to test for it.  */
+  if (is_dummy_object (expr))
+    return expr;
+
   if (TREE_CODE (expr) == COND_EXPR)
     return build3 (COND_EXPR,
 		   TREE_TYPE (expr),
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype39.C b/gcc/testsuite/g++.dg/cpp0x/decltype39.C
new file mode 100644
index 0000000..4676d2d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype39.C
@@ -0,0 +1,19 @@ 
+// PR c++/53788
+// { dg-do compile { target c++11 } }
+
+struct t { static const bool value = true; };
+struct f { static const bool value = false; };
+
+template<typename T>
+struct has_static {
+  template<typename X>
+  static t check(X*, decltype(T::fun())* = 0); // { dg-error "without object" }
+  static f check(...);
+
+  typedef decltype(check((T*)(0))) ret;
+  static const bool value = ret::value;
+};
+
+struct test { int fun() { return 0; } };
+
+bool b = has_static<test>::value;
diff --git a/gcc/testsuite/g++.dg/diagnostic/method1.C b/gcc/testsuite/g++.dg/diagnostic/method1.C
index 4a78104..0e7c580 100644
--- a/gcc/testsuite/g++.dg/diagnostic/method1.C
+++ b/gcc/testsuite/g++.dg/diagnostic/method1.C
@@ -10,7 +10,7 @@  template <class T>
 void
 bar ()
 {
-  A::foo ().anything;	// { dg-error "request for member" }
+  A::foo ().anything;	// { dg-error "without object" }
 }
 
 void
@@ -18,5 +18,3 @@  baz ()
 {
   bar <int> ();
 }
-
-// { dg-prune-output "without object" }