public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace
@ 2013-04-02 21:16 wd11 at leicester dot ac.uk
  2013-11-16 16:31 ` [Bug c++/56820] " redi at gcc dot gnu.org
  2013-11-16 16:33 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: wd11 at leicester dot ac.uk @ 2013-04-02 21:16 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56820
           Summary: elaborated-type-specifier friend incorrectly looked up
                    beyond innermost enclosing namespace
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: wd11@leicester.ac.uk


Created attachment 29781
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29781
errorneous C++ source which compiles

gcc (4.7 & 4.8) using -std=c++11 incorrectly looks up unqualified template
friends (not template-id) outside of the innermost enclosing namespace.
According to 7.3.1.2, 

"If the name in a friend declaration is neither qualified nor a template-id and
the declaration is a function or an elaborated-type-specifier, the lookup to
determine whether the entity has been previously declared shall not consider
any scopes outside the innermost enclosing namespace."

For example, in this simple code

namespace outer {
  template<typename> class A;
  namespace details {
    template<typename> class B
    {
      template<typename> friend class A;
    };
  }
}

template class outer::details::B must not befriend (but does to with gcc)
template class outer::A, because the latter is not member of the innermost
inclosing namespace. In order to befriend outer::A, the friend declaration
would need to be qualified, i.e. template<typename> friend class outer::A;

-----------------------

I attach a simple test program which triggers the error: it compiles although
it shouldn't. output from g++ -v:

Using built-in specs.
COLLECT_GCC=/opt/local/bin/g++-mp-4.8
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12
Configured with: ../gcc-4.8-20130321/configure --prefix=/opt/local
--build=x86_64-apple-darwin12
--enable-languages=c,c++,objc,obj-c++,fortran,java
--libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-4.8
--with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local
--with-cloog=/opt/local --enable-cloog-backend=isl
--disable-cloog-version-check --enable-stage1-checking --disable-multilib
--enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as
--with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar
--with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts
gcc48 4.8-20130321_0'
Thread model: posix
gcc version 4.8.0 20130321 (prerelease) (MacPorts gcc48 4.8-20130321_0) 

compilation command line (on max OS 10.8):
g++ -std=c++11 -Wextra -Wall -pedantic simple_test.cc

output: working executable writing
  a.foo(4) = 120
to stderr.


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

* [Bug c++/56820] elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace
  2013-04-02 21:16 [Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace wd11 at leicester dot ac.uk
@ 2013-11-16 16:31 ` redi at gcc dot gnu.org
  2013-11-16 16:33 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-16 16:31 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-11-16
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Confirmed.

namespace outer
{
  template<class T> struct B;

  namespace inner
  {
    template<class U> class A
    {
      template<class T> friend struct B;

      A() {}
    };
  }

  template<class T> struct B
  {
    B() { inner::A<int> a; }
  };
}

outer::B<int> b;


The friend declaration only matches outer::B when both A and B are class
templates. If either is a non-template then the friend declaration correctly
declares outer::inner::B.


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

* [Bug c++/56820] elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace
  2013-04-02 21:16 [Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace wd11 at leicester dot ac.uk
  2013-11-16 16:31 ` [Bug c++/56820] " redi at gcc dot gnu.org
@ 2013-11-16 16:33 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-16 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gafunchal at gmail dot com

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 59151 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2013-11-16 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-02 21:16 [Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace wd11 at leicester dot ac.uk
2013-11-16 16:31 ` [Bug c++/56820] " redi at gcc dot gnu.org
2013-11-16 16:33 ` redi at gcc dot gnu.org

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