Bug 94534 - ICE declaring unnamed nested struct as friend
Summary: ICE declaring unnamed nested struct as friend
Status: RESOLVED DUPLICATE of bug 96652
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-04-08 19:41 UTC by Nicholas Muggio
Modified: 2021-07-24 01:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-04-09 00:00:00


Attachments
Preprocessed source to reproduce (186 bytes, text/plain)
2020-04-08 19:41 UTC, Nicholas Muggio
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicholas Muggio 2020-04-08 19:41:55 UTC
Created attachment 48244 [details]
Preprocessed source to reproduce

Attempting to friend an unnamed, nested struct within a template class produces a segfault in the compiler.

This might be related, though doesn't seem to be quite the same: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87616

This code reproduces the error on all versions I could test (5.5.0, 7.5.0, 8.4.0, 9.2.1):

template<typename T>
class Demo
{
  struct
  {
    Demo* p;
  } payload{this};
  friend decltype(payload);
};

int main()
{
  Demo<int> d;
}

Output of `gcc -v -save-temps -std=c++11 broken.cpp`:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.2.1-17ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.2.1 20191102 (Ubuntu 9.2.1-17ubuntu1~18.04.1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE broken.cpp -mtune=generic -march=x86-64 -std=c++11 -fpch-preprocess -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -o broken.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/9"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 /home/nick/include
 /usr/include/c++/9
 /usr/include/x86_64-linux-gnu/c++/9
 /usr/include/c++/9/backward
 /usr/lib/gcc/x86_64-linux-gnu/9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/cc1plus -fpreprocessed broken.ii -quiet -dumpbase broken.cpp -mtune=generic -march=x86-64 -auxbase broken -std=c++11 -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -o broken.s
GNU C++11 (Ubuntu 9.2.1-17ubuntu1~18.04.1) version 9.2.1 20191102 (x86_64-linux-gnu)
        compiled by GNU C version 9.2.1 20191102, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++11 (Ubuntu 9.2.1-17ubuntu1~18.04.1) version 9.2.1 20191102 (x86_64-linux-gnu)
        compiled by GNU C version 9.2.1 20191102, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.19-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 33caeb1da5df6f896d4e495951c13eae
broken.cpp: In instantiation of ‘class Demo<int>’:
broken.cpp:13:13:   required from here
broken.cpp:7:5: internal compiler error: Segmentation fault
    7 |   } payload{this};
      |     ^~~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.
Comment 1 Martin Liška 2020-04-09 06:27:55 UTC
Confirmed, it's very old (at least 4.8.0+).
Comment 2 Andrew Pinski 2021-07-24 01:30:56 UTC
Fixed in GCC 11.
Comment 3 Andrew Pinski 2021-07-24 01:32:12 UTC
Dup of bug 96652 which committed a testcase.

*** This bug has been marked as a duplicate of bug 96652 ***