aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-12-17 21:49:58 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2018-12-17 21:49:58 +0000
commitf4d458f3fab13daa8a8adbc7165ee4a7050db3f6 (patch)
tree2c6206affa21424fe0236ece52816cb41f2b1ef8 /gcc/cp
parent693ad66b86dcadc9764a2ef4365902b153560dde (diff)
downloadgcc-f4d458f3fab13daa8a8adbc7165ee4a7050db3f6.zip
gcc-f4d458f3fab13daa8a8adbc7165ee4a7050db3f6.tar.gz
gcc-f4d458f3fab13daa8a8adbc7165ee4a7050db3f6.tar.bz2
PR c++/52321 print note for static_cast to/from incomplete type
PR c++/52321 * typeck.c (build_static_cast): Print a note when the destination type or the operand is a pointer/reference to incomplete class type. From-SVN: r267219
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c17
2 files changed, 21 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d12173e..a7ec887 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-12-17 Jonathan Wakely <jwakely@redhat.com>
+
+ PR c++/52321
+ * typeck.c (build_static_cast): Print a note when the destination
+ type or the operand is a pointer/reference to incomplete class type.
+
2018-12-16 Jakub Jelinek <jakub@redhat.com>
PR c++/88482
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index ac0c811..47ddad1 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -7348,8 +7348,21 @@ build_static_cast (tree type, tree oexpr, tsubst_flags_t complain)
}
if (complain & tf_error)
- error ("invalid static_cast from type %qT to type %qT",
- TREE_TYPE (expr), type);
+ {
+ error ("invalid static_cast from type %qT to type %qT",
+ TREE_TYPE (expr), type);
+ if ((TYPE_PTR_P (type) || TYPE_REF_P (type))
+ && CLASS_TYPE_P (TREE_TYPE (type))
+ && !COMPLETE_TYPE_P (TREE_TYPE (type)))
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (TREE_TYPE (type))),
+ "class type %qT is incomplete", TREE_TYPE (type));
+ tree expr_type = TREE_TYPE (expr);
+ if (TYPE_PTR_P (expr_type))
+ expr_type = TREE_TYPE (expr_type);
+ if (CLASS_TYPE_P (expr_type) && !COMPLETE_TYPE_P (expr_type))
+ inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (expr_type)),
+ "class type %qT is incomplete", expr_type);
+ }
return error_mark_node;
}