diff mbox

[C++] PR 54165

Message ID 501DA869.6090004@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Aug. 4, 2012, 10:55 p.m. UTC
Hi,

Marc noticed that this issue, where we are using an available templated 
conversion function for a cast to void, apparently can be rather easily 
attacked by moving the convert_to_void case a bit earlier in 
build_static_cast_1, that is before the 
perform_direct_initialization_if_possible call. I had a cursory look to 
other uses of convert_to_void elsewhere, actually moved the code, booted 
and tested successfully on x86_64-linux. Makes sense?

Thanks,
Paolo.

///////////////////////////////
/cp
2012-08-05  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-05  Marc Glisse  <marc.glisse@inria.fr>
	    Paolo Carlini  <paolo.carlini@oracle.com>

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

Comments

Jason Merrill Aug. 5, 2012, 11:13 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/conversion/void2.C
===================================================================
--- testsuite/g++.dg/conversion/void2.C	(revision 0)
+++ testsuite/g++.dg/conversion/void2.C	(revision 0)
@@ -0,0 +1,16 @@ 
+// PR c++/54165
+
+struct A
+{
+  template<typename T>
+  operator T()
+  {
+    T l[];
+  }
+};
+
+int main()
+{
+  A a;
+  (void)a;
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 190144)
+++ cp/typeck.c	(working copy)
@@ -6053,6 +6053,12 @@  build_static_cast_1 (tree type, tree expr, bool c_
 
   /* [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_
 
   /* [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