This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/48101 improve errors for invalid container specializations


On 22/11/17 11:23 +0100, Rainer Orth wrote:
Hi Jonathan,

This uses static_assert to improve the errors when attempting to
instantiate invalid specializations of containers, e.g. set<const T>,
or unordered_set<int, equal_to<int>, hash<int>> (which mixes up the
order of the hasher and equality predicate arguments).

This means instead of more than 100 lines of confusing errors for
https://wandbox.org/permlink/kL1YVNVOzrAsLPyS we get only this:

In file included from /home/jwakely/gcc/8/include/c++/8.0.0/set:61:0,
                from s.cc:2:
/home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_set.h: In instantiation of ‘class std::set<const int>’:
s.cc:8:18:   required from here
/home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_set.h:108:7: error: static assertion failed: std::set must have a non-const, non-volatile value_type
      static_assert(is_same<typename remove_cv<_Key>::type, _Key>::value,
      ^~~~~~~~~~~~~
In file included from /home/jwakely/gcc/8/include/c++/8.0.0/unordered_set:46:0,
                from s.cc:1:
/home/jwakely/gcc/8/include/c++/8.0.0/bits/hashtable.h: In instantiation of ‘class std::_Hashtable<int, int, std::allocator<int>, std::__detail::_Identity, std::hash<int>, std::equal_to<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, true, false> >’:
/home/jwakely/gcc/8/include/c++/8.0.0/bits/unordered_set.h:898:18:   required from ‘class std::unordered_multiset<int, std::equal_to<int>, std::hash<int> >’
s.cc:10:53:   required from here
/home/jwakely/gcc/8/include/c++/8.0.0/bits/hashtable.h:195:7: error: static assertion failed: hash function must be invocable with an argument of key type
      static_assert(__is_invocable<const _H1&, const _Key&>{},
      ^~~~~~~~~~~~~
/home/jwakely/gcc/8/include/c++/8.0.0/bits/hashtable.h:197:7: error: static assertion failed: key equality predicate must be invocable with two arguments of key type
      static_assert(__is_invocable<const _Equal&, const _Key&, const _Key&>{},
      ^~~~~~~~~~~~~

Tested powerpc64le-linux, committed to trunk.

this broke Go bootstrap, it seems.  Seen on i386-pc-solaris2.11 as of
r255048:

In file included from /var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/map:60,
                from /vol/gcc/src/hg/trunk/local/gcc/go/go-system.h:36,
                from /vol/gcc/src/hg/trunk/local/gcc/go/gofrontend/ast-dump.cc:7:
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_tree.h: In instantiation of 'class std::_Rb_tree<Import_init*, Import_init*, std::_Identity<Import_init*>, Import_init_lt, std::allocator<Import_init*> >':
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_set.h:133:17:   required from 'class std::set<Import_init*, Import_init_lt>'
/vol/gcc/src/hg/trunk/local/gcc/go/gofrontend/gogo.h:127:37:   required from here
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_tree.h:452:7: error: static assertion failed: comparison object must be invocable with two arguments of key type
      static_assert(__is_invocable<const _Compare&, const _Key&, const _Key&>{},
      ^~~~~~~~~~~~~
In file included from /var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/map:60,
                from /vol/gcc/src/hg/trunk/local/gcc/go/go-system.h:36,
                from /vol/gcc/src/hg/trunk/local/gcc/go/gofrontend/escape.cc:7:
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_tree.h: In instantiation of 'class std::_Rb_tree<Import_init*, Import_init*, std::_Identity<Import_init*>, Import_init_lt, std::allocator<Import_init*> >':
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_set.h:133:17:   required from 'class std::set<Import_init*, Import_init_lt>'
/vol/gcc/src/hg/trunk/local/gcc/go/gofrontend/gogo.h:127:37:   required from here
/var/gcc/regression/trunk/11.4-gcc/build/prev-i386-pc-solaris2.11/libstdc++-v3/include/bits/stl_tree.h:452:7: error: static assertion failed: comparison object must be invocable with two arguments of key type
      static_assert(__is_invocable<const _Compare&, const _Key&, const _Key&>{},
      ^~~~~~~~~~~~~

This is PR83102. I'm going to relax the checks, but the Go
frontend still needs to be fixed.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]