re PR c++/48557 ([C++0x][SFINAE] Hard errors with void as operand of binary built...
authorJason Merrill <jason@redhat.com>
Thu, 14 Apr 2011 15:00:07 +0000 (11:00 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 14 Apr 2011 15:00:07 +0000 (11:00 -0400)
PR c++/48557
* typeck.c (cp_build_binary_op): Don't decay void operands.

From-SVN: r172433

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/sfinae14.C [new file with mode: 0644]

index 0833125b4700b769952d243eeea47d71c542207a..1b60dd439dd95b4c87caf1c5f7974ac17e67350f 100644 (file)
@@ -1,5 +1,8 @@
 2011-04-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/48557
+       * typeck.c (cp_build_binary_op): Don't decay void operands.
+
        PR c++/48446
        * decl.c (compute_array_index_type): Use get_temp_regvar instead
        of variable_size.
index ecd7d41fc72a4f6d3310084211304ffa9375de01..b0e211058f2a78d0baed669e46b4fce57da700d4 100644 (file)
@@ -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);
     }
 
index 080d29bc40f677c94fc708388a86c72cd1433eb3..8a5f5ae90695f8e3f4069d74f19ca9f64ba6bffb 100644 (file)
@@ -1,5 +1,7 @@
 2011-04-14  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/sfinae14.C: New.
+
        * g++.dg/ext/vla10.C: New.
 
 2011-04-14  Richard Guenther  <rguenther@suse.de>
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae14.C b/gcc/testsuite/g++.dg/cpp0x/sfinae14.C
new file mode 100644 (file)
index 0000000..305f96e
--- /dev/null
@@ -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)