https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64440 --- Comment #2 from Chengnian Sun --- (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: 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: List-Archive: List-Post: List-Help: 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" 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: 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 #include 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) =================================================================