Hi,

given in particular Richard Smith' analysis here:

http://stackoverflow.com/questions/29871138/constexpr-is-not-allowed-in-declaration-of-friend-template-specialization/29957648#29957648

I think it's pretty straightforward that we don't have a good reason to reject constexpr friend declarations. In practice the most recent compilers I have at hand all agree.

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
/cp
2015-06-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/65977
        * decl.c (grokfndecl): Allow constexpr declarations of friend
        template specializations.


/testsuite
2015-06-29  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/65977
        * g++.dg/cpp0x/constexpr-friend-3.C: New.
        * g++.dg/cpp0x/constexpr-friend-2.C: Adjust.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 225123)
+++ cp/decl.c   (working copy)
@@ -7738,15 +7738,12 @@ grokfndecl (tree ctype,
            }
 
          if (inlinep & 1)
-           error ("%<inline%> is not allowed in declaration of friend "
-                  "template specialization %qD",
-                  decl);
-         if (inlinep & 2)
-           error ("%<constexpr%> is not allowed in declaration of friend "
-                  "template specialization %qD",
-                  decl);
-         if (inlinep)
-           return NULL_TREE;
+           {
+             error ("%<inline%> is not allowed in declaration of friend "
+                    "template specialization %qD",
+                    decl);
+             return NULL_TREE;
+           }
        }
     }
 
Index: testsuite/g++.dg/cpp0x/constexpr-friend-2.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-friend-2.C (revision 225123)
+++ testsuite/g++.dg/cpp0x/constexpr-friend-2.C (working copy)
@@ -3,5 +3,5 @@
 template<typename T> void f(T);
 
 template <class T> class A {
-  friend constexpr void f<>(int);  // { dg-error "'constexpr' is not allowed" }
+  friend constexpr void f<>(int);
 };
Index: testsuite/g++.dg/cpp0x/constexpr-friend-3.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-friend-3.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-friend-3.C (working copy)
@@ -0,0 +1,21 @@
+// PR c++/65977
+// { dg-do compile { target c++11 } }
+
+template<__SIZE_TYPE__>
+class bitset;
+
+template<__SIZE_TYPE__ N>
+constexpr bool operator==(const bitset<N>&, const bitset<N>&) noexcept;
+
+template<__SIZE_TYPE__ N>
+class bitset
+{
+  friend constexpr bool operator== <>(const bitset<N>&,
+                                     const bitset<N>&) noexcept;
+};
+
+template<__SIZE_TYPE__ N>
+constexpr bool operator==(const bitset<N>&, const bitset<N>&) noexcept
+{
+  return true;
+}

Reply via email to