This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50586] New: Template argument of type "pointer to function" of a template class causes usage error if template is instantiated with pointer-to-private-static-member-function
- From: "mouchtaris at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 01 Oct 2011 09:35:12 +0000
- Subject: [Bug c++/50586] New: Template argument of type "pointer to function" of a template class causes usage error if template is instantiated with pointer-to-private-static-member-function
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50586
Bug #: 50586
Summary: Template argument of type "pointer to function" of a
template class causes usage error if template is
instantiated with
pointer-to-private-static-member-function
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mouchtaris@gmail.com
Created attachment 25390
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25390
A small test file exhibiting the error.
If there is a declared template class, which accepts a pointer-to-function as a
non-type template parameter:
//////////////////////////
template <int (*f)(void)>
struct caller
{ int operator () (void) const { return (*f)(); } };
//////////////////////////
and is instantiated in a class with a pointer to a private static member
function:
//////////////////////////
class A {
static int f (void) { return 0; }
public:
caller<&f> get;
};
//////////////////////////
then G++ reports that "f" is private when used in the context of
caller::operator().
I haven't found anything in the standard that would impose this restriction.
(As a cue, this was reported as an error as well in older version of the vc
compiler, but in version 16.00 it is not an error any more)
I am attaching a small test file. I am not attaching any preprocessed file, as
there is no need. No preprocessor directives are used in this test.
I hope this has not been dealt before.
----------------- Detailed information -------------------
*** Compiler version: ***
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/spare/root/libexec/gcc/i686-pc-linux-gnu/4.6.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.6.1/configure --prefix=/spare/root
Thread model: posix
gcc version 4.6.1 (GCC)
*** Compilation command: ***
g++ -ansi -pedantic -Wall -Wextra t.cpp
*** Compiler output: ***
t.cpp: In member function 'int caller<f>::operator()() const [with int (* f)()
= A::f]':
t.cpp:26: instantiated from here
t.cpp:13: error: 'static int A::f()' is private
t.cpp:5: error: within this context