public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mouchtaris at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
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
Date: Sat, 01 Oct 2011 09:35:00 -0000	[thread overview]
Message-ID: <bug-50586-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2011-10-01  9:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-01  9:35 mouchtaris at gmail dot com [this message]
2011-10-01 15:18 ` [Bug c++/50586] " daniel.kruegler at googlemail dot com
2011-10-01 22:34 ` paolo.carlini at oracle dot com
2013-06-16  9:03 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-50586-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).