This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/79522] std::regex_match always returns false


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

Jim Michaels <jmichae3 at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #3 from Jim Michaels <jmichae3 at yahoo dot com> ---
(In reply to Jonathan Wakely from comment #2)
> You did get them swapped. Obviously the regex "abcdefg" can't match "def".
> 
> But even in your second example the behaviour is correct, std::regex_match
> matches the entire string, not any part of it. "def" doesn't match "abcdefg"
> it only matches part of it. Use std::regex_search for that.
> 
> (And "I don't know how C++ works" is still not a bug)

that was a lam, not a response.
this is a valid bug in at least comment #2. UNLESS in a regex /regex/ is
required. that I did not try. so let's try it. different regexes have different
requirements. some you have to just have 2 of the same character at both ends.
I am not some programming dweeb. yeah, I get stuff wrong sometimes, oftentimes
in fact, but I like my code as good as I can get it. and std::regex_match is
supposed to return a bool, which in iostream just comes out as a 0 or 1 I found
out.  so it's great for test rigs. (think: autoconf for fun?)

the documentation does not spell out such a syntax as /regex/.
there is probably a bug in the regex state machine, because it's failing 100%
of the time in my tests. what about your tests? did you apply any?

std::regex should be SO EASY to use. this should have been a no-brainer. I used
a manual.

so here is test#3:

#include <regex>
#include <iostream>
int main(void) {
        std::cout<<"none of these should fail."<<std::endl;
        if
(!std::regex_match("def",std::regex("abcdefg",std::regex_constants::extended))
{std::cout<<"test 1 failed"<<std::endl;} else {std::cout<<"test 1
failed"<<std::endl;}
        if
(std::regex_match("abcdefg",std::regex("def",std::regex_constants::extended)))
{std::cout<<"test 2 failed"<<std::endl;} else {std::cout<<"test 2
failed"<<std::endl;}
        if
(!std::regex_match("def",std::regex("/abcdefg/",std::regex_constants::extended)))
{std::cout<<"test 3 failed"<<std::endl;} else {std::cout<<"test 3
failed"<<std::endl;}
        if
(std::regex_match("abcdefg",std::regex("/def/",std::regex_constants::extended)))
{std::cout<<"test 4 succeeded"<<std::endl;} else {std::cout<<"test 4
failed"<<std::endl;}
        return 0;
}



 Wed 02/15/2017 15:53:17.17 L:\projects\find\1.0\win>ut
none of these should fail.
test 1 failed
test 2 failed
test 3 failed
test 4 failed

 Wed 02/15/2017 15:53:24.12 L:\projects\find\1.0\win>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]