aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorPaolo Carlini <paolo@gcc.gnu.org>2013-07-10 16:45:25 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2013-07-10 16:45:25 +0000
commitdfeadaa00be8251addff242849f6165ea9ee480c (patch)
tree75c055db7e0b64c63a205638547a013fa6c62169 /gcc/testsuite
parent87e356bada28a71fd101dce4512564ff6cb8fb15 (diff)
downloadgcc-dfeadaa00be8251addff242849f6165ea9ee480c.zip
gcc-dfeadaa00be8251addff242849f6165ea9ee480c.tar.gz
gcc-dfeadaa00be8251addff242849f6165ea9ee480c.tar.bz2
re PR c++/57869 ([C++11] Casting a object pointer to a function pointer should not warn about a forbidden conversion)
/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
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/conversion/dr195.C17
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/reinterpret_cast1.C6
-rw-r--r--gcc/testsuite/g++.dg/expr/cast2.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C25
5 files changed, 49 insertions, 9 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 82502f5..520818f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/g++.dg/conversion/dr195.C b/gcc/testsuite/g++.dg/conversion/dr195.C
index 8502c15..cb26623 100644
--- a/gcc/testsuite/g++.dg/conversion/dr195.C
+++ b/gcc/testsuite/g++.dg/conversion/dr195.C
@@ -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
index 0000000..7c0463e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast1.C
@@ -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");
diff --git a/gcc/testsuite/g++.dg/expr/cast2.C b/gcc/testsuite/g++.dg/expr/cast2.C
index 1ccda2b..f3c18d5 100644
--- a/gcc/testsuite/g++.dg/expr/cast2.C
+++ b/gcc/testsuite/g++.dg/expr/cast2.C
@@ -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
index 0000000..8cc5966
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C
@@ -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" }
+}