public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: "Daniel Krügler" <daniel.kruegler@gmail.com>
Cc: GCC <gcc@gcc.gnu.org>
Subject: Re: Design question LWG 2861: basic_string should require that charT match traits::char_type
Date: Mon, 13 Mar 2017 10:56:00 -0000	[thread overview]
Message-ID: <CAH6eHdRCuM17tr-fvBB0JF0G4GqO8jYtp25B92fy3ce_DA+g7A@mail.gmail.com> (raw)
In-Reply-To: <CAGNvRgDeqGG=39HVhs6-7mzLPxdhHGgBxySnjWEwT6O-wKUXYQ@mail.gmail.com>

On 12 March 2017 at 13:21, Daniel Krügler <daniel.kruegler@gmail.com> wrote:
> 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?

Not at this stage of gcc7 development. If the silly code compile fine
then we risk breaking working code, and we're too close to a release
to do that.

We can reconsider for gcc8 (but even then, the code has undefined
behaviour, so it would be a QoI choice whether to reject it or just
accept it, as we do for containers where Alloc::value_type doesn't
match the container's value_type).

  reply	other threads:[~2017-03-13 10:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-12 13:21 Daniel Krügler
2017-03-13 10:56 ` Jonathan Wakely [this message]
2017-03-13 11:33   ` Daniel Krügler
2017-03-13 17:31     ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdRCuM17tr-fvBB0JF0G4GqO8jYtp25B92fy3ce_DA+g7A@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=daniel.kruegler@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).