0

I'm on CentOS 7, using gcc version 4.8.5 20150623, compiling with the -std=c++11 flag. My code is as such: (note that I am using namespace std;)

bool compare_regex(const std::string & detection, std::string regstr)
{
        bool found = false;
        regex reg_matcher(regstr, std::regex_constants::extended);
        smatch m;
        if (regex_search(detection,m,reg_matcher)){
            found = true;               
        }
        else{
            log_print("REGEX NOT MATCHED.");
        }
        return found;
}

This code does not return true, even when I call it with detection = "The year 1864 was a year I tested my code on string" and regstr=18. I've tried more complicated regexes as well, but none of them work. What might be going wrong?

Hal T
  • 527
  • 7
  • 22
  • This function produces UB; control flow can leave the function without a value being returned. *"Flowing off the end of a function [...] results in undefined behavior in a value-returning function."* – cdhowie Apr 11 '17 at 16:21
  • forgot to copy the end of my code, fixing. – Hal T Apr 11 '17 at 16:25

0 Answers0