[Bug c++/51213] [C++11][DR 1170] Access control checking has to be done under SFINAE conditions

jyasskin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 27 01:33:00 GMT 2012


--- Comment #3 from Jeffrey Yasskin <jyasskin at gcc dot gnu.org> 2012-04-27 01:31:49 UTC ---
This looks like the root cause. along with r174464, of a regression in C++11
mode from 4.6->4.7 on the following program:

$ cat test.cc
#include <utility>
class Uncopyable {  // 2
  Uncopyable(const Uncopyable&);  // 3
  Uncopyable() = default;
struct ContainsUncopyable {
  std::pair<Uncopyable, int> pv;  // 8
void foo() {
  ContainsUncopyable c;  // 11
$ ~/gcc-4.6-svn/bin/g++-4.6pre --version
g++-4.6pre (GCC) 4.6.4 20120412 (prerelease)
$ g++-4.6pre -c -std=c++0x test.cc
$ ~/gcc-4.7-svn/bin/g++-4.7pre --version
g++-4.7pre (GCC) 4.7.1 20120412 (prerelease)
$ g++-4.7pre -c -std=c++11 test.cc
.../include/c++/4.7.1/type_traits: In substitution of ‘template<class _From1,
class _To1> static decltype ((__test_aux<_To1>(declval<_From1>()), std::__s
finae_types::__one())) std::__is_convertible_helper<_From, _To,
false>::__test(int) [with _From1 = _From1; _To1 = _To1; _From = const
Uncopyable&; _To = Uncopyable] [with _From1 = const Uncopyable&; _To1 =
.../include/c++/4.7.1/type_traits:1258:70:   required from ‘constexpr const
bool std::__is_convertible_helper<const Uncopyable&, Uncopyable, false>::valu
.../include/c++/4.7.1/type_traits:1263:12:   required from ‘struct
std::is_convertible<const Uncopyable&, Uncopyable>’
.../include/c++/4.7.1/type_traits:116:12:   required from ‘struct
std::__and_<std::is_convertible<const Uncopyable&, Uncopyable>,
st int&, int> >’
.../include/c++/4.7.1/bits/stl_pair.h:113:38:   required from here
test.cc:3:3: error: ‘Uncopyable::Uncopyable(const Uncopyable&)’ is private
In file included from .../include/c++/4.7.1/bits/move.h:57:0,
                 from .../include/c++/4.7.1/bits/stl_pair.h:61,
                 from .../include/c++/4.7.1/utility:72,
                 from test.cc:1:
.../include/c++/4.7.1/type_traits:1252:2: error: within this context

The workaround is to use =delete instead of access control to create
non-copyable classes in C++11 mode.

More information about the Gcc-bugs mailing list