Patchwork C++ PATCH for c++/48557 (SFINAE failure with void operands)

login
register
mail settings
Submitter Jason Merrill
Date April 14, 2011, 2:57 p.m.
Message ID <4DA70B4F.2000705@redhat.com>
Download mbox | patch
Permalink /patch/91247/
State New
Headers show

Comments

Jason Merrill - April 14, 2011, 2:57 p.m.
We were just failing to check complain for this one error.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit e807a327e3e667c8d79356cf644e493fbb82033f
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 13 18:14:45 2011 -0400

    	PR c++/48557
    	* typeck.c (cp_build_binary_op): Don't decay void operands.
Jason Merrill - April 14, 2011, 2:58 p.m.
On 04/14/2011 10:57 AM, Jason Merrill wrote:
> We were just failing to check complain for this one error.

Er, actually that's the next patch.  For this one, we were complaining 
in decay_conversion about misuse of void.  I noticed that some other 
places avoid calling that on void operands, so that's what I did here as 
well.

Jason

Patch

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ecd7d41..b0e2110 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3646,16 +3646,16 @@  cp_build_binary_op (location_t location,
       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
       || code == TRUTH_XOR_EXPR)
     {
-      if (!really_overloaded_fn (op0))
+      if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
 	op0 = decay_conversion (op0);
-      if (!really_overloaded_fn (op1))
+      if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
 	op1 = decay_conversion (op1);
     }
   else
     {
-      if (!really_overloaded_fn (op0))
+      if (!really_overloaded_fn (op0) && !VOID_TYPE_P (TREE_TYPE (op0)))
 	op0 = default_conversion (op0);
-      if (!really_overloaded_fn (op1))
+      if (!really_overloaded_fn (op1) && !VOID_TYPE_P (TREE_TYPE (op1)))
 	op1 = default_conversion (op1);
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae14.C b/gcc/testsuite/g++.dg/cpp0x/sfinae14.C
new file mode 100644
index 0000000..305f96e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae14.C
@@ -0,0 +1,27 @@ 
+// PR c++/48557
+// { dg-options -std=c++0x }
+
+template<class T>
+struct add_rval_ref
+{
+  typedef T&& type;
+};
+
+template<>
+struct add_rval_ref<void>
+{
+  typedef void type;
+};
+
+template<class T>
+typename add_rval_ref<T>::type create();
+
+template<class T, class U,
+  class = decltype(create<T>() + create<U>())
+>
+char f(int);
+
+template<class, class>
+char (&f(...))[2];
+
+static_assert(sizeof(f<void, int>(0)) != 1, "Error");  // (a)