re PR c++/61745 (template friend for dyadic operator- is only accepted if the monadic...
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 18 Sep 2014 09:15:25 +0000 (09:15 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 18 Sep 2014 09:15:25 +0000 (09:15 +0000)
2014-09-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61745
* g++.dg/template/pr61745.C: New.

From-SVN: r215345

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

index 28157924c47bbc051002edbe101bc751018a120a..60a402f1243228d8c7b99bfce708f3c4858cc5b9 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61745
+       * g++.dg/template/pr61745.C: New.
+
 2014-09-17  Marek Polacek  <polacek@redhat.com>
 
        PR c/61854
diff --git a/gcc/testsuite/g++.dg/template/pr61745.C b/gcc/testsuite/g++.dg/template/pr61745.C
new file mode 100644 (file)
index 0000000..0f7c280
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/61745
+
+template <typename INT,INT P> class Zp;
+
+template <typename INT,INT P> 
+Zp<INT,P> operator-(const Zp<INT,P>& a, const Zp<INT,P>& b);
+
+template <typename INT,INT P>
+class Zp {
+public:
+  static const INT p = P;
+private:
+  INT val;
+public:
+  Zp() : val(0) {}
+  Zp( INT x ) : val(x%p) { if (x < 0 ) x+= p; }
+
+  // this compiles only if the following definition is moved
+  // AFTER the friend declaration
+  Zp  operator-() const { return Zp(p-val); }
+  friend Zp<INT,P> operator- <>(const Zp<INT,P>& a, const Zp<INT,P>& b); // { dg-error "declaration|expected" }
+};