]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/57869 ([C++11] Casting a object pointer to a function pointer should not...
authorPaolo Carlini <paolo@gcc.gnu.org>
Wed, 10 Jul 2013 16:45:25 +0000 (16:45 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 10 Jul 2013 16:45:25 +0000 (16:45 +0000)
/c-family
2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/57869
* c.opt: Add Wconditionally-supported.

/cp
2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/57869
* typeck.c (build_reinterpret_cast_1): With -Wconditionally-supported
warn about casting between pointer-to-function and pointer-to-object.

/gcc
2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/57869
* doc/invoke.texi: Document -Wconditionally-supported.

/testsuite
2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/57869
* g++.dg/cpp0x/reinterpret_cast1.C: New.
* g++.dg/warn/Wconditionally-supported-1.C: Likewise.
* g++.dg/conversion/dr195.C: Update.
* g++.dg/expr/cast2.C: Likewise.

From-SVN: r200876

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/dr195.C
gcc/testsuite/g++.dg/cpp0x/reinterpret_cast1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/expr/cast2.C
gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C [new file with mode: 0644]

index e5a233f87411cbe1703e8d4a41badd195d6a8f33..354e15cc5f6c2be173495367c21c8f5423e5001a 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/57869
+       * doc/invoke.texi: Document -Wconditionally-supported.
+
 2013-07-10  Georg-Johann Lay  <avr@gjlay.de>
 
        PR target/57844
index ec47ffbbf5a7571e3931a821c485eb625df2e6e0..0506e55dd47b8cec87b850fde40fabf62c12be45 100644 (file)
@@ -1,3 +1,8 @@
+2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/57869
+       * c.opt: Add Wconditionally-supported.
+
 2013-07-04  Joern Rennecke <joern.rennecke@embecosm.com>
 
        PR c/57821
@@ -17,7 +22,7 @@
        * c-cppbuiltin.c (c_cpp_builtins): Likewise.
        * c-opts.c (c_common_post_options): Likewise.
 
-2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>  
+2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
        * array-notation-common.c (length_mismatch_in_expr): Changed the
        parameter type's from a dynamic array to a vec_tree.  Also removed
@@ -70,7 +75,7 @@
        (find_inv_trees): Likewise.
        (replace_inv_trees): Likewise.
        (find_correct_array_notation_type): Likewise.
-       
+
 2013-05-28  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
        * c-common.c (c_define_builtins): When cilkplus is enabled, the
index 857813474c9a3e66a87e0bf024fc975422964dfb..9690a087fd3569dc9b134d5cda944c77885bbb45 100644 (file)
@@ -319,6 +319,10 @@ Wcomments
 C ObjC C++ ObjC++ Warning Alias(Wcomment)
 Synonym for -Wcomment
 
+Wconditionally-supported
+C++ ObjC++ Var(warn_conditionally_supported) Warning
+Warn for conditionally-supported constructs
+
 Wconversion
 C ObjC C++ ObjC++ Var(warn_conversion) Warning
 Warn for implicit type conversions that may change a value
index 7da759a6c9d2615b4b535d2513e322cdcffd7c59..3dede369473194e22a2fdc9a059b0a60377a8343 100644 (file)
@@ -1,3 +1,9 @@
+2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/57869
+       * typeck.c (build_reinterpret_cast_1): With -Wconditionally-supported
+       warn about casting between pointer-to-function and pointer-to-object.
+
 2013-07-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/57402
index 6f7d489287918bd4c2604b649ebde7507bf8d1c3..1d504ad96d61e27c382c5e5df4de6704fa481b0b 100644 (file)
@@ -6722,12 +6722,12 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p,
   else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
           || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
     {
-      if (pedantic && (complain & tf_warning))
-       /* Only issue a warning, as we have always supported this
-          where possible, and it is necessary in some cases.  DR 195
-          addresses this issue, but as of 2004/10/26 is still in
-          drafting.  */
-       warning (0, "ISO C++ forbids casting between pointer-to-function and pointer-to-object");
+      if (complain & tf_warning)
+       /* C++11 5.2.10 p8 says that "Converting a function pointer to an
+          object pointer type or vice versa is conditionally-supported."  */
+       warning (OPT_Wconditionally_supported,
+                "casting between pointer-to-function and pointer-to-object "
+                "is conditionally-supported");
       return fold_if_not_in_template (build_nop (type, expr));
     }
   else if (TREE_CODE (type) == VECTOR_TYPE)
index 1496d3042afbe1229a91c5a30456398edae4d2a3..dd34233989e0fd638af35e20db7daa9bac1ef371 100644 (file)
@@ -237,7 +237,7 @@ Objective-C and Objective-C++ Dialects}.
 -Waggressive-loop-optimizations -Warray-bounds @gol
 -Wno-attributes -Wno-builtin-macro-redefined @gol
 -Wc++-compat -Wc++11-compat -Wcast-align  -Wcast-qual  @gol
--Wchar-subscripts -Wclobbered  -Wcomment @gol
+-Wchar-subscripts -Wclobbered  -Wcomment -Wconditionally-supported  @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-cpp  -Wno-deprecated  @gol
 -Wno-deprecated-declarations -Wdisabled-optimization  @gol
 -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
@@ -4393,6 +4393,11 @@ programs.
 Warn for variables that might be changed by @samp{longjmp} or
 @samp{vfork}.  This warning is also enabled by @option{-Wextra}.
 
+@item -Wconditionally-supported @r{(C++ and Objective-C++ only)}
+@opindex Wconditionally-supported
+@opindex Wno-conditionally-supported
+Warn for conditionally-supported (C++11 [intro.defs]) constructs.
+
 @item -Wconversion
 @opindex Wconversion
 @opindex Wno-conversion
index 82502f5f9015f938b8d88929dcbb8fec10b708cd..520818f0199945481fa7125b394cfe1fbc502730 100644 (file)
@@ -1,3 +1,11 @@
+2013-07-10  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/57869
+       * g++.dg/cpp0x/reinterpret_cast1.C: New.
+       * g++.dg/warn/Wconditionally-supported-1.C: Likewise.
+       * g++.dg/conversion/dr195.C: Update.
+       * g++.dg/expr/cast2.C: Likewise.
+
 2013-07-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/57757
index 8502c1578b69c3b98cf2dd74993999f686b3e6d8..cb26623e11fdb7a07e98974b8df1c4235158534a 100644 (file)
@@ -1,11 +1,12 @@
 // Copyright (C) 2004 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 20 Oct 2004 <nathan@codesourcery.com>
 
-// DR 195 will allow conversions between function and object pointers
-// under some circumstances. It is in drafting, so we don't implement
-// it (yet).
+// DR 195 was about allowing conversions between function and object
+// pointers under some circumstances.  The issue got resolved for C++11,
+// which, in 5.2.10 p8 says that: "Converting a function pointer to an
+// object pointer type or vice versa is conditionally-supported."
 
-// This checks we warn when being pedantic.
+// This checks we don't warn anymore with -pedantic.
 
 typedef void (*PF)(void);
 typedef void *PV;
@@ -18,12 +19,12 @@ void foo ()
   PO po;
 
   /* the following two will almost definitly be ok with 195.  */
-  pf = reinterpret_cast <PF>(pv); // { dg-warning "casting between" "" }
-  pv = reinterpret_cast <PV>(pf); // { dg-warning "casting between" "" }
+  pf = reinterpret_cast <PF>(pv);
+  pv = reinterpret_cast <PV>(pf);
 
   /* the following two might or might not be ok with 195.  */
-  pf = reinterpret_cast <PF>(po); // { dg-warning "casting between" "" }
-  po = reinterpret_cast <PO>(pf); // { dg-warning "casting between" "" }
+  pf = reinterpret_cast <PF>(po);
+  po = reinterpret_cast <PO>(pf);
 
   /* These will never be ok, as they are implicit.  */
   pv = pf; // { dg-error "invalid conversion" "" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast1.C b/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast1.C
new file mode 100644 (file)
index 0000000..7c0463e
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/57869
+// { dg-do compile { target c++11 } }
+
+void* po = 0;
+void (*pf)() = reinterpret_cast<decltype(pf)>(po);
+static_assert(sizeof(po) >= sizeof(pf), "Conversion not supported");
index 1ccda2b4804bc9ba64ec3bd3129a5a9a024a6320..f3c18d5feec391d55aaac2998564496e9d0a7128 100644 (file)
@@ -1,5 +1,5 @@
 void (*p)();
 
 void f() {
-  (void *)p; // { dg-warning "forbids cast" }
+  (void *)p;
 }
diff --git a/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C
new file mode 100644 (file)
index 0000000..8cc5966
--- /dev/null
@@ -0,0 +1,25 @@
+// { dg-options "-Wconditionally-supported" }
+
+// DR 195 was about allowing conversions between function and object
+// pointers under some circumstances.  The issue got resolved for C++11,
+// which, in 5.2.10 p8 says that: "Converting a function pointer to an 
+// object pointer type or vice versa is conditionally-supported."
+
+// This checks we warn with -Wconditionally-supported.
+
+typedef void (*PF)(void);
+typedef void *PV;
+typedef int *PO;
+
+void foo ()
+{
+  PF pf;
+  PV pv;
+  PO po;
+
+  pf = reinterpret_cast <PF>(pv); // { dg-warning "conditionally-supported" }
+  pv = reinterpret_cast <PV>(pf); // { dg-warning "conditionally-supported" }
+
+  pf = reinterpret_cast <PF>(po); // { dg-warning "conditionally-supported" }
+  po = reinterpret_cast <PO>(pf); // { dg-warning "conditionally-supported" }
+}