re PR c++/14263 (Cryptic diagnostic for cast from virtual base class not using dynamic_cast)

/cp
2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/14263
	* class.c (build_base_path): Improve diagnostic.

/testsuite
2013-07-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/14263
	* g++.dg/inherit/virtual10.C: New.

From-SVN: r200718
This commit is contained in:
Paolo Carlini 2013-07-05 16:28:35 +00:00 committed by Paolo Carlini
parent 1c6269d3f5
commit 128be7f933
4 changed files with 46 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2013-07-05 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/14263
* class.c (build_base_path): Improve diagnostic.
2013-07-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/38634

View File

@ -291,9 +291,31 @@ build_base_path (enum tree_code code,
if (code == MINUS_EXPR && v_binfo)
{
if (complain & tf_error)
error ("cannot convert from base %qT to derived type %qT via "
"virtual base %qT", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
BINFO_TYPE (v_binfo));
{
if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (v_binfo)))
{
if (want_pointer)
error ("cannot convert from pointer to base class %qT to "
"pointer to derived class %qT because the base is "
"virtual", BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
else
error ("cannot convert from base class %qT to derived "
"class %qT because the base is virtual",
BINFO_TYPE (binfo), BINFO_TYPE (d_binfo));
}
else
{
if (want_pointer)
error ("cannot convert from pointer to base class %qT to "
"pointer to derived class %qT via virtual base %qT",
BINFO_TYPE (binfo), BINFO_TYPE (d_binfo),
BINFO_TYPE (v_binfo));
else
error ("cannot convert from base class %qT to derived "
"class %qT via virtual base %qT", BINFO_TYPE (binfo),
BINFO_TYPE (d_binfo), BINFO_TYPE (v_binfo));
}
}
return error_mark_node;
}

View File

@ -1,3 +1,8 @@
2013-07-05 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/14263
* g++.dg/inherit/virtual10.C: New.
2013-07-04 Joern Rennecke <joern.rennecke@embecosm.com>
PR c/57821

View File

@ -0,0 +1,11 @@
// PR c++/14263
struct A { };
struct B : virtual A { };
int main()
{
A* p = new B;
B* q = static_cast<B*>(p); // { dg-error "cannot convert from pointer to base class 'A' to pointer to derived class 'B' because the base is virtual" }
}