aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-class3.C12
-rw-r--r--gcc/testsuite/g++.dg/template/non-dependent18.C19
3 files changed, 32 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 88ab233..d4a07a7 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
new file mode 100644
index 0000000..68b50b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class3.C
@@ -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" }
diff --git a/gcc/testsuite/g++.dg/template/non-dependent18.C b/gcc/testsuite/g++.dg/template/non-dependent18.C
new file mode 100644
index 0000000..3e15568
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/non-dependent18.C
@@ -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" }
+};