c++: Add testcase for SFINAE w/ p[N] and incomplete type [PR101239]
authorPatrick Palka <ppalka@redhat.com>
Mon, 27 Dec 2021 15:01:42 +0000 (10:01 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 27 Dec 2021 15:01:42 +0000 (10:01 -0500)
The r12-6123 fix for SFINAE with p+N and incomplete type also fixed
the analogous issue with p[N].

PR c++/101239

gcc/testsuite/ChangeLog:

* g++.dg/template/sfinae32a.C: New test.

gcc/testsuite/g++.dg/template/sfinae32a.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/template/sfinae32a.C b/gcc/testsuite/g++.dg/template/sfinae32a.C
new file mode 100644 (file)
index 0000000..e9dbe88
--- /dev/null
@@ -0,0 +1,24 @@
+// PR c++/101239
+// { dg-do compile { target c++11 } }
+
+template<class T, int N> auto f(T* p) -> decltype(p[N]);
+template<class T, int N> auto f(T* p) -> decltype(p[-N]);
+template<class T, int N> auto f(T* p) -> decltype(N[p]);
+template<class T, int N> void f(T* p);
+
+template<class T> auto g(T* p, int n) -> decltype(p[n]);
+template<class T> auto g(T* p, int n) -> decltype(p[-n]);
+template<class T> auto g(T* p, int n) -> decltype(n[p]);
+template<class T> void g(T* p, int n);
+
+struct Incomplete;
+
+int main() {
+  f<Incomplete,  0>(nullptr);
+  f<Incomplete,  1>(nullptr);
+  f<Incomplete, -1>(nullptr);
+  f<Incomplete,  7>(nullptr);
+  f<Incomplete, -7>(nullptr);
+
+  g<Incomplete>(nullptr, 0);
+}