re PR c++/54165 (Cast to "void" should not implicitly call conversion functions)
authorMarc Glisse <marc.glisse@inria.fr>
Mon, 6 Aug 2012 09:49:39 +0000 (11:49 +0200)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 6 Aug 2012 09:49:39 +0000 (09:49 +0000)
/cp
2012-08-06  Marc Glisse  <marc.glisse@inria.fr>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/54165
* typeck.c (build_static_cast_1): Move the conversion to void case
before the perform_direct_initialization_if_possible call.

/testsuite
2012-08-06  Marc Glisse  <marc.glisse@inria.fr>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/54165
* g++.dg/conversion/void2.C: New.

Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>
From-SVN: r190175

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

index f57769d..86c9097 100644 (file)
@@ -1,3 +1,10 @@
+2012-08-06  Marc Glisse  <marc.glisse@inria.fr>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/54165
+       * typeck.c (build_static_cast_1): Move the conversion to void case
+       before the perform_direct_initialization_if_possible call.
+
 2012-08-03  Marc Glisse  <marc.glisse@inria.fr>
 
        * pt.c (tsubst_copy_and_build): Handle VECTOR_TYPE like scalars.
index d7a719f..25f37e8 100644 (file)
@@ -6053,6 +6053,12 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
 
   /* [expr.static.cast]
 
+     Any expression can be explicitly converted to type cv void.  */
+  if (TREE_CODE (type) == VOID_TYPE)
+    return convert_to_void (expr, ICV_CAST, complain);
+
+  /* [expr.static.cast]
+
      An expression e can be explicitly converted to a type T using a
      static_cast of the form static_cast<T>(e) if the declaration T
      t(e);" is well-formed, for some invented temporary variable
@@ -6074,12 +6080,6 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
 
   /* [expr.static.cast]
 
-     Any expression can be explicitly converted to type cv void.  */
-  if (TREE_CODE (type) == VOID_TYPE)
-    return convert_to_void (expr, ICV_CAST, complain);
-
-  /* [expr.static.cast]
-
      The inverse of any standard conversion sequence (clause _conv_),
      other than the lvalue-to-rvalue (_conv.lval_), array-to-pointer
      (_conv.array_), function-to-pointer (_conv.func_), and boolean
index 7311f7b..371acf1 100644 (file)
@@ -1,3 +1,9 @@
+2012-08-06  Marc Glisse  <marc.glisse@inria.fr>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/54165
+       * g++.dg/conversion/void2.C: New.
+
 2012-08-06  Tom de Vries  <tom@codesourcery.com>
 
        * gcc.dg/tree-ssa/vrp78.c: New test.
diff --git a/gcc/testsuite/g++.dg/conversion/void2.C b/gcc/testsuite/g++.dg/conversion/void2.C
new file mode 100644 (file)
index 0000000..9bd6d9f
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/54165
+
+struct A
+{
+  template<typename T>
+  operator T()
+  {
+    T l[];
+  }
+};
+
+int main()
+{
+  A a;
+  (void)a;
+}