public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "chengniansun at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/64440] -Wdiv-by-zero false negative on const variables
Date: Tue, 30 Dec 2014 07:53:00 -0000	[thread overview]
Message-ID: <bug-64440-4-lC9xG2WPHI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-64440-4@http.gcc.gnu.org/bugzilla/>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 4593 bytes --]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64440

--- Comment #2 from Chengnian Sun <chengniansun at gmail dot com> ---

(In reply to Andrew Pinski from comment #1)
> In C, const int is not a constant expression and -Wdiv-by-zero only warns
> about integer constant expressions.

Thanks for your reply. It seems GCC sometimes does consider "const int" for
other types of warnings (but not for -Wdiv-by-zero). See the following, with
-O3, GCC warns that the left shift count is negative.  

$: cat t.c
int f(int a) {
  const char c = -4;
  return a << c;
}
$: gcc-trunk -Wall -c t.c -O3
t.c: In function ‘f’:
t.c:3:12: warning: left shift count is negative
   return a << c;
            ^
$:
>From gcc-bugs-return-471917-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Dec 30 09:32:04 2014
Return-Path: <gcc-bugs-return-471917-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21269 invoked by alias); 30 Dec 2014 09:32:03 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21236 invoked by uid 48); 30 Dec 2014 09:31:58 -0000
From: "kariya_mitsuru at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/64441] New: A match_results returns an incorrect sub_match if the sub_match::matched is false
Date: Tue, 30 Dec 2014 09:32:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: kariya_mitsuru at hotmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created
Message-ID: <bug-64441-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-12/txt/msg02924.txt.bz2
Content-length: 2015

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd441

            Bug ID: 64441
           Summary: A match_results returns an incorrect sub_match if the
                    sub_match::matched is false
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

Created attachment 34362
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4362&actioníit
g++ -v

Please see the following sample.

====================================== sample code
=====================================#include <iostream>
#include <regex>

int main()
{
    const char s[] = "abc";
    const std::regex re("(\\d+)|(\\w+)");

    std::cmatch m;
    std::regex_search(s, m, re);
    std::cout << std::boolalpha;
    for (size_t i = 0, n = m.size(); i < n; ++i) {
        auto&& sub = m[i];
        std::cout << i << ":" << sub.matched << ", str = '" << sub.str() << "',
"
            "range = [" << sub.first - s << ", " << sub.second - s << ")" <<
std::endl;
    }
}
===================================================================================================================== output ============================0:true, str = 'abc', range = [0, 3)
1:false, str = '', range = [-140734305427376, -140734305427376)
2:true, str = 'abc', range = [0, 3)
=================================================================
cf. http://melpon.org/wandbox/permlink/SBoMF5UKYYa38Y4N


The C++11 standard 28.10[re.results]/p.4 says, "Otherwise matched is false, and
members first and second point to the end of the sequence that was searched."

So, I think that the output should be

============================= output ============================0:true, str = 'abc', range = [0, 3)
1:false, str = '', range = [3, 3)
2:true, str = 'abc', range = [0, 3)
=================================================================

  parent reply	other threads:[~2014-12-30  7:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-30  2:27 [Bug c/64440] New: " chengniansun at gmail dot com
2014-12-30  3:01 ` [Bug c/64440] " pinskia at gcc dot gnu.org
2014-12-30  7:53 ` chengniansun at gmail dot com [this message]
2014-12-30 12:31 ` manu at gcc dot gnu.org
2015-01-06 15:23 ` mpolacek at gcc dot gnu.org
2015-01-06 16:07 ` mpolacek at gcc dot gnu.org
2015-01-07  8:22 ` mpolacek at gcc dot gnu.org
2015-01-07  8:22 ` mpolacek 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-64440-4-lC9xG2WPHI@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).