-- >8 --
It makes more sense to point at the derived type (that didn't specify
the base class).
gcc/cp/ChangeLog:
* constraint.cc (diagnose_trait_expr): Use t2's location for
is_base_of, is_pointer_interconvertible_base_of, and
is_virtual_base_of.
gcc/testsuite/ChangeLog:
* g++.dg/ext/is_virtual_base_of_diagnostic2.C: Adjust
diagnostic.
Signed-off-by: Nathaniel Shead <[email protected]>
---
gcc/cp/constraint.cc | 9 ++++-----
.../g++.dg/ext/is_virtual_base_of_diagnostic2.C | 4 ++--
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 60095d3c4f7..90c35023953 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3135,7 +3135,7 @@ diagnose_trait_expr (location_t loc, tree expr, tree args)
is_xible (MODIFY_EXPR, t1, t2, /*explain=*/true);
break;
case CPTK_IS_BASE_OF:
- inform (decl_loc, "%qT is not a base of %qT", t1, t2);
+ inform (location_of (t2), "%qT is not a base of %qT", t1, t2);
break;
case CPTK_IS_BOUNDED_ARRAY:
inform (loc, "%qT is not a bounded array", t1);
@@ -3236,7 +3236,8 @@ diagnose_trait_expr (location_t loc, tree expr, tree args)
inform (loc, "%qT is not an object type", t1);
break;
case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF:
- inform (decl_loc, "%qT is not a pointer-interconvertible base of %qT",
+ inform (location_of (t2),
+ "%qT is not a pointer-interconvertible base of %qT",
t1, t2);
break;
case CPTK_IS_POD:
@@ -3295,9 +3296,7 @@ diagnose_trait_expr (location_t loc, tree expr, tree args)
inform (decl_loc, "%qT is not a union", t1);
break;
case CPTK_IS_VIRTUAL_BASE_OF:
- inform (decl_loc, "%qT is not a virtual base of %qT", t1, t2);
- if (CLASS_TYPE_P (t2))
- inform (location_of (t2), "%qT declared here", t2);
+ inform (location_of (t2), "%qT is not a virtual base of %qT", t1, t2);
break;
case CPTK_IS_VOLATILE:
inform (loc, "%qT is not a volatile type", t1);
diff --git a/gcc/testsuite/g++.dg/ext/is_virtual_base_of_diagnostic2.C
b/gcc/testsuite/g++.dg/ext/is_virtual_base_of_diagnostic2.C
index ac28121d49f..20d268570df 100644
--- a/gcc/testsuite/g++.dg/ext/is_virtual_base_of_diagnostic2.C
+++ b/gcc/testsuite/g++.dg/ext/is_virtual_base_of_diagnostic2.C
@@ -8,6 +8,6 @@ struct is_virtual_base_of {
static_assert(is_virtual_base_of<int, int>::value, ""); // { dg-error
"assert" }
// { dg-message "'int' is not a virtual base of 'int'" "" { target *-*-* }
.-1 }
-struct A {}; // { dg-message "'A' is not a virtual base of 'B'" }
-struct B : A {}; // { dg-message "declared here" }
+struct A {};
+struct B : A {}; // { dg-message "'A' is not a virtual base of 'B'" }
static_assert(is_virtual_base_of<A, B>::value, ""); // { dg-error "assert" }