From 7e422c4f04827a80a296dd080001927beea2634f Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 8 May 2014 14:30:56 +0000 Subject: [PATCH] re PR c++/13981 (Give message about incomplete class that might be implicitly upcasted.) /cp 2014-05-08 Paolo Carlini PR c++/13981 * typeck.c (convert_for_assignment): Provide an inform for pointers to incomplete class types. /testsuite 2014-05-08 Paolo Carlini PR c++/13981 * g++.dg/diagnostic/pr13981.C: New. From-SVN: r210217 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/diagnostic/pr13981.C | 12 ++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/g++.dg/diagnostic/pr13981.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8a7f18c1169e..3d400bbb7540 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-05-08 Paolo Carlini + + PR c++/13981 + * typeck.c (convert_for_assignment): Provide an inform for pointers + to incomplete class types. + 2014-05-07 Paolo Carlini PR c++/61083 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7b28a9a58695..b933b96fc3e5 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8094,6 +8094,14 @@ convert_for_assignment (tree type, tree rhs, default: gcc_unreachable(); } + if (TYPE_PTR_P (rhstype) + && TYPE_PTR_P (type) + && CLASS_TYPE_P (TREE_TYPE (rhstype)) + && CLASS_TYPE_P (TREE_TYPE (type)) + && !COMPLETE_TYPE_P (TREE_TYPE (rhstype))) + inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL + (TREE_TYPE (rhstype))), + "class type %qT is incomplete", TREE_TYPE (rhstype)); } return error_mark_node; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ad7a652e3f9d..ffbec5d2abfa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-05-08 Paolo Carlini + + PR c++/13981 + * g++.dg/diagnostic/pr13981.C: New. + 2014-05-08 Marc Glisse PR tree-optimization/59100 diff --git a/gcc/testsuite/g++.dg/diagnostic/pr13981.C b/gcc/testsuite/g++.dg/diagnostic/pr13981.C new file mode 100644 index 000000000000..1b8a028d948d --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/pr13981.C @@ -0,0 +1,12 @@ +// PR c++/13981 + +struct A {}; +struct B; // { dg-message "is incomplete" } + +void func( A *a ); + +int main() +{ + B *b = 0; + func(b); // { dg-error "cannot convert" } +} -- 2.47.3