public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42328] rejects valid friend
       [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
@ 2015-03-27 18:22 ` paolo.carlini at oracle dot com
  2015-03-27 19:32 ` richard-gccbugzilla at metafoo dot co.uk
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 18:22 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gcc-bugs at gcc dot gnu.org        |paolo.carlini at oracle dot com

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thus, I understand we could close this as worksforme, Richard?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
       [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
  2015-03-27 18:22 ` [Bug c++/42328] rejects valid friend paolo.carlini at oracle dot com
@ 2015-03-27 19:32 ` richard-gccbugzilla at metafoo dot co.uk
  2015-03-27 20:33 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2015-03-27 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
Yes, I think this is ill-formed (although the standard is very unclear about
this). I think the declaration

  template<typename T> friend void freeList<T, baz>::foo();

would declare the member 'foo' of the class template partial specialization
freeList<T, baz> to be a friend, but no such partial specialization has been
defined. If I add

  class baz;
  template<typename T> class freeList<T, baz> { void foo(); };

before the definition of 'baz', then GCC and EDG accept, which I think is
correct behavior.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
       [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
  2015-03-27 18:22 ` [Bug c++/42328] rejects valid friend paolo.carlini at oracle dot com
  2015-03-27 19:32 ` richard-gccbugzilla at metafoo dot co.uk
@ 2015-03-27 20:33 ` paolo.carlini at oracle dot com
  2015-03-28 12:35 ` paolo at gcc dot gnu.org
  2015-03-28 12:56 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thanks Richard. Then I'm going to add both testcases before closing the bug.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
       [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2015-03-27 20:33 ` paolo.carlini at oracle dot com
@ 2015-03-28 12:35 ` paolo at gcc dot gnu.org
  2015-03-28 12:56 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 10+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-03-28 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Sat Mar 28 10:28:14 2015
New Revision: 221751

URL: https://gcc.gnu.org/viewcvs?rev=221751&root=gcc&view=rev
Log:
2015-03-28  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/42328
    * g++.dg/template/friend58.C: New.
    * g++.dg/template/friend59.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/template/friend58.C
    trunk/gcc/testsuite/g++.dg/template/friend59.C
Modified:
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
       [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2015-03-28 12:35 ` paolo at gcc dot gnu.org
@ 2015-03-28 12:56 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-28 12:56 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to work|                            |4.8.0, 4.9.0, 5.0
         Resolution|---                         |WORKSFORME

--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
  2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2009-12-08  9:57 ` redi at gcc dot gnu dot org
@ 2009-12-08 15:20 ` igodard at pacbell dot net
  4 siblings, 0 replies; 10+ messages in thread
From: igodard at pacbell dot net @ 2009-12-08 15:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from igodard at pacbell dot net  2009-12-08 15:20 -------
Both proposals befriend more than the minimum actually needed by program
semantics. The former befriends any member of freeList<bar, baz>, not just foo;
the latter any member of any freeList at all. In addition, the former requires
that bar be a resolved type. Bar is resolved in the simplified example I
submitted, but in the original baz is itself a template and bar is a class
argument, and you get a diagnostic on a friend of the form of the first
suggestion. That's why the friend is a template, not just freeList<bar, baz> -
the original code was more like:

template<typename U>
class   baz : protected freeList<U, baz>,
              protected freeList<aType, baz>,
              protected freeList<bType, baz>,
              < more, where all but U were resolved types >
 {
template<typename T>
friend
void    freeList<T, baz>::foo();
    < body of baz >
    };

but was simplified for the report.


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
  2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2009-12-08  2:16 ` igodard at pacbell dot net
@ 2009-12-08  9:57 ` redi at gcc dot gnu dot org
  2009-12-08 15:20 ` igodard at pacbell dot net
  4 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-12-08  9:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2009-12-08 09:57 -------

What's wrong with

class   baz : protected freeList<bar, baz> {
    void    frob() {}
    friend class freeList<bar, baz>;
    };

or

class   baz : protected freeList<bar, baz> {
    void    frob() {}
    template<typename T, typename U> friend void freeList<T, U>::foo();
    };


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
  2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
  2009-12-07 23:14 ` [Bug c++/42328] " pinskia at gcc dot gnu dot org
  2009-12-07 23:35 ` paolo dot carlini at oracle dot com
@ 2009-12-08  2:16 ` igodard at pacbell dot net
  2009-12-08  9:57 ` redi at gcc dot gnu dot org
  2009-12-08 15:20 ` igodard at pacbell dot net
  4 siblings, 0 replies; 10+ messages in thread
From: igodard at pacbell dot net @ 2009-12-08  2:16 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1769 bytes --]



------- Comment #3 from igodard at pacbell dot net  2009-12-08 02:16 -------
I stand corrected about Comeau - I missed the error and only noticed the
warning. Regardless, there must be some way to solve this problem:

template<typename T, typename U>
class   freeList {
public:
    void foo();
    };

class   bar {};

class   baz : protected freeList<bar, baz> {
    void    frob() {}
    };

template<>
void    freeList<bar, baz>::foo() { static_cast<baz*>(this)->frob(); }

int main() {
    baz b;
    return 0;
    }

gets you:

s3:~/ootbc/personal/ivan$ g++ foo.cc
foo.cc: In member function ‘void freeList<T, U>::foo() [with T = bar, U =
baz]’:
foo.cc:14: error: ‘freeList<bar, baz>’ is an inaccessible base of ‘baz’

I believe this diagnostic is legitimate. If I recall, in earlier versions of
the compiler (4.0.X? Don't remember) the template "friend" declaration in the
original report exposed the base class to the friend function and the code
(with the friend) compiled without error. Then we upgraded the compiler and it
stopped working. I thought this reflected a new bug and reported it. If in fact
the friend is invalid (just not previously caught) then fine - but then how do
you get the original cast to the base to work?

In short, if the friend declaration I wrote is illegal, how otherwise do you
turn a member function of a base class into a friend of a derived class of that
base?

I realize that helping me in my code is not your job, but any help would be
greatly appreciated. And if it is not in fact possible perhaps some of the
language mavens among you might raise the issue with the standards group,
because what I was trying is certainly a reasonable thing to want to do.


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
  2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
  2009-12-07 23:14 ` [Bug c++/42328] " pinskia at gcc dot gnu dot org
@ 2009-12-07 23:35 ` paolo dot carlini at oracle dot com
  2009-12-08  2:16 ` igodard at pacbell dot net
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-12-07 23:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2009-12-07 23:35 -------
Likewise SunStudio and Icc reject it.


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/42328] rejects valid friend
  2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
@ 2009-12-07 23:14 ` pinskia at gcc dot gnu dot org
  2009-12-07 23:35 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-12-07 23:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-12-07 23:13 -------
Comeau C++ also rejects this code with the following error message:
"ComeauTest.c", line 12: error: declaration is incompatible with nontype
          "<unnamed> freeList<T, U>::foo [with T=T, U=baz]" (declared at line
          12)
  void    freeList<T, baz>::foo();
                            ^


-- 


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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-03-28 10:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42328-4@http.gcc.gnu.org/bugzilla/>
2015-03-27 18:22 ` [Bug c++/42328] rejects valid friend paolo.carlini at oracle dot com
2015-03-27 19:32 ` richard-gccbugzilla at metafoo dot co.uk
2015-03-27 20:33 ` paolo.carlini at oracle dot com
2015-03-28 12:35 ` paolo at gcc dot gnu.org
2015-03-28 12:56 ` paolo.carlini at oracle dot com
2009-12-07 23:04 [Bug c++/42328] New: " igodard at pacbell dot net
2009-12-07 23:14 ` [Bug c++/42328] " pinskia at gcc dot gnu dot org
2009-12-07 23:35 ` paolo dot carlini at oracle dot com
2009-12-08  2:16 ` igodard at pacbell dot net
2009-12-08  9:57 ` redi at gcc dot gnu dot org
2009-12-08 15:20 ` igodard at pacbell dot net

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