diff options
author | Patrick Palka <ppalka@redhat.com> | 2024-07-19 13:48:12 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2024-07-19 13:48:12 -0400 |
commit | 2ee70c9f83a1033f2897a35bff9e9ffdd03cc651 (patch) | |
tree | e9d43cb50e11f204e2bc37c8aeb59389ead29c96 | |
parent | 9116490c1b03dac18f10e42df03731a3aed0b4e9 (diff) | |
download | gcc-2ee70c9f83a1033f2897a35bff9e9ffdd03cc651.zip gcc-2ee70c9f83a1033f2897a35bff9e9ffdd03cc651.tar.gz gcc-2ee70c9f83a1033f2897a35bff9e9ffdd03cc651.tar.bz2 |
c++: xobj fn call without obj [PR115783]
The code path for rejecting an object-less call to a non-static member
function should also consider xobj member functions (so that we correctly
reject the below calls with a "cannot call member function without object"
diagnostic).
PR c++/115783
gcc/cp/ChangeLog:
* call.cc (build_new_method_call): Generalize METHOD_TYPE
check to DECL_OBJECT_MEMBER_FUNCTION_P.
gcc/testsuite/ChangeLog:
* g++.dg/cpp23/explicit-obj-diagnostics11.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r-- | gcc/cp/call.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C | 48 |
2 files changed, 49 insertions, 1 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index a5d3426..40cb582 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -11855,7 +11855,7 @@ build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args, fn); } - if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE + if (DECL_OBJECT_MEMBER_FUNCTION_P (fn) && !DECL_CONSTRUCTOR_P (fn) && is_dummy_object (instance)) { diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C new file mode 100644 index 0000000..cc2571f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C @@ -0,0 +1,48 @@ +// PR c++/115783 +// { dg-do compile { target c++23 } } + +struct A { + int f(this auto); + + static void s() { + f(); // { dg-error "without object" } + } +}; + +int n = A::f(); // { dg-error "without object" } + +struct B { + void ns() { + A::f(); // { dg-error "without object" } + } + + static void s() { + A::f(); // { dg-error "without object" } + } +}; + +template<class T> +struct C { + void ns() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "without object" } + } + + static void s() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "without object" } + }; +}; + +template struct C<A>; + +template<class T> +struct D : T { + void ns() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "not a member of 'B'" } + } +}; + +template struct D<B>; // { dg-message "required from here" } +template struct D<A>; // { dg-bogus "required from here" } |