public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35927]  New: befriending a whole template in another namespace fails
@ 2008-04-14  2:18 mec at google dot com
  2008-04-14 14:22 ` [Bug c++/35927] " bangerth at dealii dot org
  0 siblings, 1 reply; 3+ messages in thread
From: mec at google dot com @ 2008-04-14  2:18 UTC (permalink / raw)
  To: gcc-bugs

In this program, Beta::Gamma declares ::Alpha as a friend, but the friendship
does not work.

===

mec@hollerith:~/exp-friend$ cat z1.cc
template <typename T>
void Alpha(T* a) { a->Delta(); }

namespace Beta {

class Gamma {
 public:
  template <typename T> friend void ::Alpha(T*);

 private:
  void Delta();
};

}

int main() {
  Beta::Gamma* a = new Beta::Gamma;
  ::Alpha(a);
}

bash: /home/mec/gcc-4.2.1/install/bing++: No such file or directory
mec@hollerith:~/exp-friend$ /home/mec/gcc-4.2.1/install/bin/g++ -O2 -Wall -c
z1.cc
z1.cc: In function 'void Alpha(T*) [with T = Beta::Gamma]':
z1.cc:18:   instantiated from here
z1.cc:11: error: 'void Beta::Gamma::Delta()' is private
z1.cc:2: error: within this context

mec@hollerith:~/exp-friend$ /home/mec/gcc-4.2.2/install/bin/g++ -O2 -Wall -c
z1.cc
z1.cc: In function 'void Alpha(T*) [with T = Beta::Gamma]':
z1.cc:18:   instantiated from here
z1.cc:11: error: 'void Beta::Gamma::Delta()' is private
z1.cc:2: error: within this context

mec@hollerith:~/exp-friend$ /home/mec/gcc-4.3.0/install/bin/g++ -O2 -Wall -c
z1.cc
z1.cc: In function 'void Alpha(T*) [with T = Beta::Gamma]':
z1.cc:18:   instantiated from here
z1.cc:11: error: 'void Beta::Gamma::Delta()' is private
z1.cc:2: error: within this context
mec@hollerith:~/exp-friend$ 

===

In this program, Beta::Gamma declares the specialization ::Alpha<Beta::Gamma>
as a friend.  This works.

ec@hollerith:~/exp-friend$ cat z3.cc
template <typename T>
void Alpha(T* a) { a->Delta(); }

namespace Beta {

class Gamma {
 public:
  friend void ::Alpha<Beta::Gamma>(Beta::Gamma*);

 private:
  void Delta();
};

}

int main() {
  Beta::Gamma* a = new Beta::Gamma;
  ::Alpha(a);
}

mec@hollerith:~/exp-friend$ /home/mec/gcc-4.2.1/install/bin/g++ -O2 -Wall -c
z3.cc
mec@hollerith:~/exp-friend$ /home/mec/gcc-4.2.2/install/bin/g++ -O2 -Wall -c
z3.cc
mec@hollerith:~/exp-friend$ /home/mec/gcc-4.3.0/install/bin/g++ -O2 -Wall -c
z3.cc
mec@hollerith:~/exp-friend$

===

I think z1.cc is valid, per this clause from [temp.friend]:

"A template friend declaration specifies that all specializations of that
template, whether they are implicitly instantiated (14.7.1), partially
specialized (14.5.4) or explicitly specialized (14.7.3) are friends of the
class containing the template friend declaration.

I suspect it's a bug with the namespace part of "template <typename T> friend
void ::Alpha(T*);".


-- 
           Summary: befriending a whole template in another namespace fails
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mec at google dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug c++/35927] befriending a whole template in another namespace fails
  2008-04-14  2:18 [Bug c++/35927] New: befriending a whole template in another namespace fails mec at google dot com
@ 2008-04-14 14:22 ` bangerth at dealii dot org
  0 siblings, 0 replies; 3+ messages in thread
From: bangerth at dealii dot org @ 2008-04-14 14:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at dealii dot org  2008-04-14 14:21 -------
I too believe that z1.cc is valid. icc accepts it.

Not a regression, the code fails back to 2.95.
W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-04-14 14:21:17
               date|                            |


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


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

* [Bug c++/35927] befriending a whole template in another namespace fails
       [not found] <bug-35927-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-27  0:03 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-27  0:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org |
      Known to work|                            |4.6.0, 4.6.1, 4.7.0
         Resolution|                            |FIXED

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-26 22:54:16 UTC ---
Fixed in 4.6.0.


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

end of thread, other threads:[~2011-09-26 22:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-14  2:18 [Bug c++/35927] New: befriending a whole template in another namespace fails mec at google dot com
2008-04-14 14:22 ` [Bug c++/35927] " bangerth at dealii dot org
     [not found] <bug-35927-4@http.gcc.gnu.org/bugzilla/>
2011-09-27  0:03 ` paolo.carlini at oracle dot com

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