public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Design question LWG 2861: basic_string should require that charT match traits::char_type
@ 2017-03-12 13:21 Daniel Krügler
  2017-03-13 10:56 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Krügler @ 2017-03-12 13:21 UTC (permalink / raw)
  To: GCC

I'm now working on

http://cplusplus.github.io/LWG/lwg-defects.html#2861

The new wording state is now equivalent to basic_string_view, whose
current implementation doesn't bother verifying the requirement, so
this code (which as UB) currently compiles just fine:

#include <string>
#include <string_view>

struct MyTraits : std::char_traits<char>
{
  typedef unsigned char char_type;
};

int main()
{
  std::basic_string<char, MyTraits> my_string;
  std::basic_string_view<char, MyTraits> my_string_view;
}

So the least I could do is just - nothing. But it seems to me that we
could protect users from doing such silly things by adding a
static_assert to both basic_string and basic_string_view, the former
being equivalent to

#if __cplusplus >= 201103L
      static_assert(__are_same<value_type, _CharT>::value,
                    "traits_type::char_type must be equal to _CharT");
#endif

and the latter an unconditional

      static_assert(is_same<typename _Traits::char_type, _CharT>::value,
                    "traits_type::char_type must be equal to _CharT");

Would you agree with that course of action?

Thanks,

- Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-13 17:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 13:21 Design question LWG 2861: basic_string should require that charT match traits::char_type Daniel Krügler
2017-03-13 10:56 ` Jonathan Wakely
2017-03-13 11:33   ` Daniel Krügler
2017-03-13 17:31     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).