]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Adjust location of is_*_base_of diagnostics
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 25 Oct 2025 13:01:30 +0000 (00:01 +1100)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 22 Nov 2025 23:45:11 +0000 (10:45 +1100)
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 <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constraint.cc
gcc/testsuite/g++.dg/ext/is_virtual_base_of_diagnostic2.C

index 5b7eb36b4608ca9321103ca505c5059452748d44..8efe4a45348dcc8cad88d33e836e75667b6723b1 100644 (file)
@@ -3134,7 +3134,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);
@@ -3235,7 +3235,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:
@@ -3288,9 +3289,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);
index ac28121d49f27a2c714c04b6aaa500a93298e8a5..20d268570df1ffa485358ff39bdd7041cdb54f73 100644 (file)
@@ -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" }