From f8e94a0156bb869e3b82ca063054ab052a72827b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 10 May 2018 14:57:55 -0400 Subject: [PATCH] Core issue 2310 - conversion to base of incomplete type. * class.c (build_base_path): Check COMPLETE_TYPE_P for source type. From-SVN: r260127 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/class.c | 9 +++++++++ gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e6223ae4dc3..2b9ceb29dcf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2018-05-09 Jason Merrill + Core issue 2310 - conversion to base of incomplete type. + * class.c (build_base_path): Check COMPLETE_TYPE_P for source type. + CWG 2267 - list-initialization of reference temporary * call.c (reference_binding): List-initializing a reference temporary is copy-list-initialization. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 30323f0a9f6..4616d8d3036 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -370,6 +370,15 @@ build_base_path (enum tree_code code, goto indout; } + if (!COMPLETE_TYPE_P (probe)) + { + if (complain & tf_error) + error ("cannot convert from %qT to base class %qT because %qT is " + "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo), + BINFO_TYPE (d_binfo)); + return error_mark_node; + } + /* If we're in an NSDMI, we don't have the full constructor context yet that we need for converting to a virtual base, so just build a stub CONVERT_EXPR and expand it later in bot_replace. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C new file mode 100644 index 00000000000..849ac81db78 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base6.C @@ -0,0 +1,14 @@ +// CWG issue 2310 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template struct check_derived_from { + static A a; + static constexpr B *p = &a; // { dg-error "" } + int ar[p-p+1]; +}; +struct W { int i; }; +struct Z : W +{ + check_derived_from cdf; +};