https://gcc.gnu.org/g:c2ce1b55cd91ea81be2a9c357efa2579695e9f46

commit r16-5518-gc2ce1b55cd91ea81be2a9c357efa2579695e9f46
Author: Nathaniel Shead <[email protected]>
Date:   Sun Oct 26 00:01:30 2025 +1100

    c++: Adjust location of is_*_base_of diagnostics
    
    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]>
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 gcc/cp/constraint.cc                                      | 9 ++++-----
 gcc/testsuite/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 5b7eb36b4608..8efe4a45348d 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -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);
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 ac28121d49f2..20d268570df1 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" }

Reply via email to