[Bug c++/54323] New: Friend function declaration not correctly identified with CRTP + enable_if
vince.rev at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Aug 19 15:52:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54323
Bug #: 54323
Summary: Friend function declaration not correctly identified
with CRTP + enable_if
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: vince.rev@gmail.com
Created attachment 28051
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28051
.cpp bug example
The following example involving a friend function in a Curiously Recurring
Template Pattern base class with an enable_if default template argument is not
working :
// --------------------------------------------------------------------
#include <type_traits>
// Base class definition
template<template<typename> class CRTP, typename T> class Base
{
// Friend function declaration
public:
template<template<typename> class CRTP0, typename T0, class>
friend int func(const Base<CRTP0, T0>& rhs);
// Protected test variable
protected:
int n;
};
// Friend function definition
template<template<typename> class CRTP0, typename T0,
class = typename std::enable_if<true>::type>
int func(const Base<CRTP0, T0>& rhs)
{
return rhs.n;
}
// Derived class definition
template<typename T> class Derived : public Base<Derived, T> {};
// Main
int main()
{
Derived<int> x;
func(x);
return 0;
}
// --------------------------------------------------------------------
g++ (tested with 4.6.1, 4.6.2 and 4.7.1) seems not to be able to match the
definition with the declaration of the function and return the following error
:
"int Base<Derived, int>::n' is protected"
More information about the Gcc-bugs
mailing list