public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kayhayen at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/45399] [C++0x] Warning for \0 in raw strings
Date: Mon, 08 Nov 2010 17:43:00 -0000	[thread overview]
Message-ID: <bug-45399-4-36Xr1KPTcn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-45399-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45399

--- Comment #5 from Kay Hayen <kayhayen at gmx dot de> 2010-11-08 17:43:23 UTC ---
(In reply to comment #4)
> The motivating examples in the original raw strings proposal are for
> simplifying regular expressions and HTML markup, there's no mention of binary
> blobs.
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2053.html

I tend to agree that avoiding of backslashes is already something. But raw
strings are definitely also useful to store arbitrary data.

I use them in Nuitka to store the binary blobs from marshaled constants.
Currently I have to have Python code like this to do that:

    def _encodeString( self, value ):
        delimiter = self._pickRawDelimiter( value )

        start = 'R"' + delimiter + "("
        end = ")" + delimiter + '"'

        result = start + value + end

        # Replace \n, \r and \0 in the raw strings. The \0 gives a silly
warning from
        # gcc (bug reported) and \n and \r even lead to wrong strings. Somehow
the
        # parser of the C++ doesn't yet play nice with these.

        def decide( match ):
            if match.group(0) == "\n":
                return end + r' "\n" ' + start
            elif match.group(0) == "\r":
                return end + r' "\r" ' + start
            else:
                return end + r' "\0" ' + start

        result = re.sub( "\n|\r|" + chr(0), decide, result )

As you can see, I somehow believe that "\n" and "\r" are not interpreted
correctly and replace these (should it be necessary, at least at one time it
was?) and then added the same for chr(0) later on.

I consider the necessity to do each of those a bug. In my mind all it should
take would be a delimiter not present in the string. Still I am thankful for
raw strings as those are way easier to get right than a readable Python to
plain C++ string translation.

And the intention of a C++ feature, since when did it ever come to limit its
use? I admit that files with "\0" inside are not the sane thing to write. But
for me C++ is something I generate as a temporary intermediate step. Please
provide a means to disable that warning without disabling everything, or even
stop it for raw strings.

Yours,
Kay

PS: If you are interested in what I do with Nuitka, feel free to visit
http://kayhayen24x7.homelinux.org/blog/nuitka-a-python-compiler/what-is-nuitka/


  parent reply	other threads:[~2010-11-08 17:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-45399-4@http.gcc.gnu.org/bugzilla/>
2010-10-31 10:14 ` paolo.carlini at oracle dot com
2010-11-08 11:03 ` kayhayen at gmx dot de
2010-11-08 12:19 ` redi at gcc dot gnu.org
2010-11-08 12:26 ` redi at gcc dot gnu.org
2010-11-08 17:43 ` kayhayen at gmx dot de [this message]
2010-11-08 18:32 ` redi at gcc dot gnu.org
2011-05-25  5:39 ` jason at gcc dot gnu.org
2011-05-25  7:14 ` jakub at gcc dot gnu.org
2011-06-15 18:19 ` jason at gcc dot gnu.org
2011-06-15 18:41 ` manu at gcc dot gnu.org
2011-06-16 22:15 ` jason at gcc dot gnu.org
2011-06-17  0:13 ` jason at gcc dot gnu.org

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=bug-45399-4-36Xr1KPTcn@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).