This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/65977] New: Constexpr should be allowed in declaration of friend template specialization


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65977

            Bug ID: 65977
           Summary: Constexpr should be allowed in declaration of friend
                    template specialization
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rhalbersma at gmail dot com
  Target Milestone: ---

The following code comes from this StackOverflow Q&A (note this is not related
to std::bitset, it's just a homegrown class to experiment with constexpr):
http://stackoverflow.com/q/29871138/819272

#include <cstddef>

template<std::size_t>
class bitset;

template<std::size_t N>
constexpr bool operator==(const bitset<N>&, const bitset<N>&) noexcept;

template<std::size_t N>
class bitset
{
    friend constexpr bool operator== <>(const bitset<N>&, const bitset<N>&)
noexcept;
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-- error from this piece
};

template<std::size_t N>
constexpr bool operator==(const bitset<N>&, const bitset<N>&) noexcept
{
    return true;
}

int main() {}

The error I get with -std=c++11 on gcc 4.9.1 through gcc HEAD 6.0.0 20150501 is

'constexpr' is not allowed in declaration of friend template specialization 

The same code on older gcc version (4.6 through 4.8) gives a slightly different
error

'inline' is not allowed in declaration of friend template specialization

which seems to have been introduced in 2013
https://gcc.gnu.org/ml/gcc-patches/2013-03/msg01028.html

Richard Smith's accepted answer on StackOverflow (
http://stackoverflow.com/a/29957648/819272 ) states that although constexpr
functions are implicitly inline, an inline function does not imply the inline
specifier. Therefore the above code should be valid.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]