c++: dependent bases and 'this' availability [PR103831]
Here during satisfaction of B's constraints we're failing to reject the object-less call to the non-static member function A::size ultimately because satisfaction is performed in the (access) context of the class template B, which has a dependent base, and so the any_dependent_bases_p check within build_new_method_call causes us to not reject the call. (Subsequent constexpr evaluation of the call succeeds since the function is effectively static.) This patch fixes this by refining the any_dependent_bases_p check within build_new_method_call: if we're in a context where 'this' is unavailable, then we cannot resolve the implicit object regardless of the presence of a dependent base. So let's also check current_class_ptr alongside a_d_b_p. PR c++/103831 gcc/cp/ChangeLog: * call.c (build_new_method_call): Consider dependent bases only if 'this' is available. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-class3.C: New test. * g++.dg/template/non-dependent18.C: New test.
This commit is contained in:
parent
46de918f98
commit
0378f563b0
3 changed files with 32 additions and 1 deletions
|
@ -11125,7 +11125,7 @@ build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
|
|||
we know we really need it. */
|
||||
cand->first_arg = instance;
|
||||
}
|
||||
else if (any_dependent_bases_p ())
|
||||
else if (current_class_ptr && any_dependent_bases_p ())
|
||||
/* We can't tell until instantiation time whether we can use
|
||||
*this as the implicit object argument. */;
|
||||
else
|
||||
|
|
12
gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
Normal file
12
gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
Normal file
|
@ -0,0 +1,12 @@
|
|||
// PR c++/103831
|
||||
// { dg-do compile { target c++20 } }
|
||||
|
||||
struct A {
|
||||
constexpr int size() { return 42; } // non-static
|
||||
};
|
||||
|
||||
template<class T>
|
||||
requires (T::size() == 42) // { dg-error "without object" }
|
||||
struct B : T { };
|
||||
|
||||
template struct B<A>; // { dg-error "constraint" }
|
19
gcc/testsuite/g++.dg/template/non-dependent18.C
Normal file
19
gcc/testsuite/g++.dg/template/non-dependent18.C
Normal file
|
@ -0,0 +1,19 @@
|
|||
// PR c++/103831
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
struct A {
|
||||
constexpr int size() { return 42; } // non-static
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct B : T {
|
||||
static_assert(A::size() == 42, ""); // { dg-error "without object" }
|
||||
|
||||
static int f() {
|
||||
static_assert(A::size() == 42, ""); // { dg-error "without object" }
|
||||
return A::size(); // { dg-error "without object" }
|
||||
}
|
||||
|
||||
int n = A::size();
|
||||
static const int m = A::size(); // { dg-error "without object" }
|
||||
};
|
Loading…
Add table
Reference in a new issue