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

            Bug ID: 82478
           Summary: Rejects valid access to private member type that
                    should be allowed by friend
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eieio at google dot com
  Target Milestone: ---

Created attachment 42325
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42325&action=edit
Complete source file that reproduces the issue.

Hello,

Attached is a source file that reproduces the issue. It appears that in some
contexts the friend declaration is not being honored, causing the compiler to
reject access to a private member type. If this bug turns out to be issue of
interpretation of the spec it would be helpful to understand the interpretation
so that we can discuss with our other compiler maintainers.

We reproduced this issue on various versions of GCC. For this bug submission we
used Compiler Explorer (https://gcc.godbolt.org/) to prepare the reproduction
example.

Thanks!

The following is the compiler output and settings as requested in the FAQ:

Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/gcc-7.2.0/bin/g++
Target: x86_64-linux-gnu
Configured with: ../gcc-7.2.0/configure --prefix /root/staging
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--disable-multilib --disable-bootstrap --disable-multiarch --with-arch-32=i586
--enable-clocale=gnu --enable-languages=c,c++,go,fortran --enable-ld=yes
--enable-gold=yes --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=GCC-Explorer-Build
Thread model: posix
gcc version 7.2.0 (GCC-Explorer-Build) 
COLLECT_GCC_OPTIONS='-g' '-o'
'/tmp/compiler-explorer-compiler11798-16759-19s20vn.7r70wo2yb9/output.s'
'-masm=intel' '-S' '-std=c++14' '-v' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'

/opt/compiler-explorer/gcc-7.2.0/bin/../libexec/gcc/x86_64-linux-gnu/7.2.0/cc1plus
-quiet -v -iprefix
/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/
-D_GNU_SOURCE <source> -quiet -dumpbase example.cpp -masm=intel -mtune=generic
-march=x86-64 -auxbase-strip
/tmp/compiler-explorer-compiler11798-16759-19s20vn.7r70wo2yb9/output.s -g
-std=c++14 -version -o
/tmp/compiler-explorer-compiler11798-16759-19s20vn.7r70wo2yb9/output.s
GNU C++14 (GCC-Explorer-Build) version 7.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR
version 3.1.4, MPC version 1.0.3, isl version isl-0.16.1-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../x86_64-linux-gnu/include"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/x86_64-linux-gnu"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/include"
ignoring duplicate directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/include-fixed"
ignoring nonexistent directory
"/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/x86_64-linux-gnu

/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0

/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/x86_64-linux-gnu

/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward
 /opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/include

/opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/include-fixed
 /usr/local/include
 /opt/compiler-explorer/gcc-7.2.0/bin/../lib/gcc/../../include
 /usr/include
End of search list.
GNU C++14 (GCC-Explorer-Build) version 7.2.0 (x86_64-linux-gnu)
        compiled by GNU C version 5.4.0 20160609, GMP version 6.1.0, MPFR
version 3.1.4, MPC version 1.0.3, isl version isl-0.16.1-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 365c66794fa92d1b324014f9c53ac6bc
60 : <source>:60:15: error: 'struct {anonymous}::A::PRIVATE' is private within
this context
 static_assert(HasPrivate<A>::value, "");
               ^~~~~~~~~~~~~
38 : <source>:38:12: note: declared private here
     struct PRIVATE { int a; int b; };
            ^~~~~~~
62 : <source>:62:15: error: 'struct {anonymous}::A::PRIVATE' is private within
this context
 static_assert(Outer::HasPrivate<A>::value, "");
               ^~~~~
38 : <source>:38:12: note: declared private here
     struct PRIVATE { int a; int b; };
            ^~~~~~~
Compiler exited with result code 1

Reply via email to