aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2003-06-27 16:24:49 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2003-06-27 16:24:49 +0000
commit3a73bcc6870738923820d08fbcd62774d77b4936 (patch)
treef0cc7b18d16832c35d66b6a6e97d2508d9cdf9da
parent560d4c592f6f414f6a17a9902b664933930c75fd (diff)
downloadgcc-3a73bcc6870738923820d08fbcd62774d77b4936.zip
gcc-3a73bcc6870738923820d08fbcd62774d77b4936.tar.gz
gcc-3a73bcc6870738923820d08fbcd62774d77b4936.tar.bz2
re PR c++/11332 (Spurious error with casts in ?: expression)
PR c++/11332 * typeck.c (build_static_cast): Avoid returning expressions with reference type. PR c++/11332 * g++.dg/expr/static_cast2.C: New test. From-SVN: r68580
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/expr/static_cast2.C7
4 files changed, 22 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9a22768..d0ecbdb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2003-06-26 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/11332
+ * typeck.c (build_static_cast): Avoid returning expressions with
+ reference type.
+
2003-06-26 Nathan Sidwell <nathan@codesourcery.com>
* call.c (build_op_delete_call): Use strip_array_call. Correct
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index c84cc84..6c17089 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4814,7 +4814,7 @@ build_static_cast (tree type, tree expr)
t. */
result = perform_direct_initialization_if_possible (type, expr);
if (result)
- return result;
+ return convert_from_reference (result);
/* [expr.static.cast]
@@ -4848,8 +4848,9 @@ build_static_cast (tree type, tree expr)
/* Convert from B* to D*. */
expr = build_base_path (MINUS_EXPR, build_address (expr),
base, /*nonnull=*/false);
- /* Convert the pointer to a reference. */
- return build_nop (type, expr);
+ /* Convert the pointer to a reference -- but then remember that
+ there are no expressions with reference type in C++. */
+ return convert_from_reference (build_nop (type, expr));
}
/* [expr.static.cast]
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 51bed04..190e0ef 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2003-06-26 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/11332
+ * g++.dg/expr/static_cast2.C: New test.
+
2003-06-26 Roger Sayle <roger@eyesopen.com>
Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/testsuite/g++.dg/expr/static_cast2.C b/gcc/testsuite/g++.dg/expr/static_cast2.C
new file mode 100644
index 0000000..7b5d46d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/expr/static_cast2.C
@@ -0,0 +1,7 @@
+struct B {};
+
+int main () {
+ B a;
+ (1 ? static_cast<B&>(a) :
+ *static_cast<B*>(&a));
+}