public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50126] New: g++ does not recognize a friend declaration
@ 2011-08-19 13:36 pisetta.gianni at alice dot it
  2015-03-27 18:41 ` [Bug c++/50126] " paolo.carlini at oracle dot com
  0 siblings, 1 reply; 2+ messages in thread
From: pisetta.gianni at alice dot it @ 2011-08-19 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50126
           Summary: g++ does not recognize a friend declaration
    Classification: Unclassified
           Product: gcc
           Version: 4.4.5
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pisetta.gianni@alice.it


Created attachment 25054
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25054
intermediate file

compiling the code of test.cpp:
-----------------------------------
template<class A,class B> class X {
public:    
    template<class C> X<C,B>& operator[]( const C& );
};

template<class A,class B,class C> class Y : public X<C,B> {
    friend X<C,B>& X<A,B>::template operator[]<C>( const C& );
private:
    Y( X<A,B>& object , const C& index ) : X<C,B>() {};
};

template<class A,class B> template<class C> X<C,B>& X<A,B>::operator[]( const
C& index ) {
    return *( new Y<A,B,C>( *this , index ) );
}

void test() {
    X<int,void> x;
    X<int,void>& y = x[2];
}
---------------------------------------
with the command line:
  g++ -c test.cpp -o test.cpp
report:
  ./test.cpp: In instantiation of ‘Y<int, void, int>’:
  ./test.cpp:14:   instantiated from ‘X<C, B>& X<A, B>::operator[](const C&)
with [C = int, A = int, B = void]’
  ./test.cpp:19:   instantiated from here
  ./test.cpp:8: error: ‘operator[]’ not defined
  ./test.cpp: In member function ‘X<C, B>& X<A, B>::operator[](const C&) [with
C = int, A = int, B = void]’:
  ./test.cpp:19:   instantiated from here
  ./test.cpp:10: error: ‘Y<A, B, C>::Y(X<A, B>&, const C&) [with A = int, B =
void, C = int]’ is private
  ./test.cpp:14: error: within this context

I asked on the internet and it seems that it is a valid friend declaration.
Compiling the same code with 'clang' does not report any error.
The only workaround is to use a template friend declaration like:
--------------------------------------------
template<class A,class B,class C> class Y : public X<C,B> {
    template<class CC> friend X<CC,B>& X<A,B>::operator[]( const CC& );
--------------------------------------------
but it declares every generated operator[] as friend of class Y, so it is
dangerous.

g++ version:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.4 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-targets=all --with-arch-32=i586 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)


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

* [Bug c++/50126] g++ does not recognize a friend declaration
  2011-08-19 13:36 [Bug c++/50126] New: g++ does not recognize a friend declaration pisetta.gianni at alice dot it
@ 2015-03-27 18:41 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 2+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 18:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-27
             Blocks|                            |65608
     Ever confirmed|0                           |1


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

end of thread, other threads:[~2015-03-27 18:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-19 13:36 [Bug c++/50126] New: g++ does not recognize a friend declaration pisetta.gianni at alice dot it
2015-03-27 18:41 ` [Bug c++/50126] " 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).