public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59930] New: template friend declarations, namespaces, and explicit instantiations don't mix
@ 2014-01-24  0:04 luto at mit dot edu
  0 siblings, 0 replies; only message in thread
From: luto at mit dot edu @ 2014-01-24  0:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59930

            Bug ID: 59930
           Summary: template friend declarations, namespaces, and explicit
                    instantiations don't mix
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luto at mit dot edu

namespace NS {

template<typename T>
class Holder
{
private:
    void func();

    template<typename>
    friend class User;
};

template class Holder<long>;

template<typename T>
class User
{
public:
    void method() const
    {
        Holder<T> x;
        x.func();
    }
};

} // namespace

// This one is okay, oddly.
// template class NS::Holder<long>;

void Foo()
{
    NS::User<long> decl;
    decl.method();
}

says (in trunk r207012):

$ g++-trunk -Wall -c template_friend.cc 
template_friend.cc: In instantiation of ‘void NS::User<T>::method() const [with
T = long int]’:
template_friend.cc:34:14:   required from here
template_friend.cc:7:7: error: ‘void NS::Holder<T>::func() [with T = long int]’
is private
  void func();
       ^
template_friend.cc:22:3: error: within this context
   x.func();
   ^

The 4.8 branch can't compile this either, but clang is okay with it.

Oddly, removing the namespace, removing the explicit instantiation, or moving
the explicit instantiation outside the namespace causes g++ to accept this
code.
>From gcc-bugs-return-441388-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jan 24 00:45:27 2014
Return-Path: <gcc-bugs-return-441388-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9514 invoked by alias); 24 Jan 2014 00:45:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 9468 invoked by uid 48); 24 Jan 2014 00:45:21 -0000
From: "frankhb1989 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/59931] New: Wrong wording of diagnostic about imaginary "member function type"
Date: Fri, 24 Jan 2014 00:45:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: minor
X-Bugzilla-Who: frankhb1989 at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-59931-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-01/txt/msg02530.txt.bz2
Content-length: 1342

http://gcc.gnu.org/bugzilla/show_bug.cgi?idY931

            Bug ID: 59931
           Summary: Wrong wording of diagnostic about imaginary "member
                    function type"
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frankhb1989 at gmail dot com

Case:

class C
{
public:
    void f()
    {
        void (C::*pf)() = f;
    }
};
int main(){}


a.cc: In member function 'void C::f()':
a.cc:6:21: error: cannot convert 'C::f' from type 'void (C::)()' to type 'void
(C::*)()'
    void (C::*pf)() = f;
                      ^

In short, there is no type like 'void (C::)()' in modern C++, at least in ISO
C++. The member 'C::f' here should have type 'void ()'(if it makes sense), just
as a non-member function type. The reason should be determined by the
difference between pointer types and pointer to member types, and no conversion
like function-to-pointer takes effects in it.

P.S.
Clang++ 3.0 complains about this as:
"error: cannot initialize a variable of type 'void (C::*)()' with an rvalue of
type '<bound member function type>'".
And Clang++ 3.2's:
"error: cannot initialize a variable of type 'void (C::*)()' with an rvalue of
type 'void'".


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-01-24  0:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24  0:04 [Bug c++/59930] New: template friend declarations, namespaces, and explicit instantiations don't mix luto at mit dot edu

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).