https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79661
Bug ID: 79661 Summary: Bogus "destructor is private within this context" only in C++17 mode Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sbergman at redhat dot com Target Milestone: --- At least with a recent GCC trunk build: > $ g++ --version > g++ (GCC) 7.0.1 20170220 (experimental) > Copyright (C) 2017 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > $ cat test.cc > template<typename T> struct R { R(T *); }; > struct S { > S(int); > private: > ~S(); > }; > void f() { R<S>(new S(0)); } > > $ g++ -std=c++17 -fsyntax-only test.cc > test.cc: In function ‘void f()’: > test.cc:7:24: error: ‘S::~S()’ is private within this context > void f() { R<S>(new S(0)); } > ^ > test.cc:5:2: note: declared private here > ~S(); > ^ Compilation succeeds when dropping the S constructor's int parameter (or even merely giving it a default value and removing the argument from 'new S()'), or when dropping the R<S>(...) wrapper, or when compiling as -std=c++14, or when compiling with GCC 6.3.1 (gcc-c++-6.3.1-1.fc25.x86_64). So I assume this is a bug rather than an actual C++17 requirement that I'm not aware of. (The used GCC trunk version already includes the fix for somewhat-similar bug 78469.)