This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace
- From: "wd11 at leicester dot ac.uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 02 Apr 2013 21:16:41 +0000
- Subject: [Bug c++/56820] New: elaborated-type-specifier friend incorrectly looked up beyond innermost enclosing namespace
- Auto-submitted: auto-generated
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.