[LLVMbugs] [Bug 11118] New: regex does not handle (?=^|[\n\r]) correctly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Oct 12 04:48:57 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=11118

           Summary: regex does not handle (?=^|[\n\r]) correctly
           Product: libc++
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: hhinnant at apple.com
        ReportedBy: jonathan.sauer at gmx.de
                CC: llvmbugs at cs.uiuc.edu


The following program, intended to search for #include directives in a string,
compiles using clang r141771 and libc++ r141771, but does not produce the
intended result:

#include <regex>

static const std::regex   
INCLUDE_REGEXP(R"((?=^|[\n\r])#include\s*<([^>]+)>)");

static const std::string    s = 
    "#include <A.glsl>\n"
    "attribute vec3    vertexTex0;\n"
    "//#include <DontFindThisOne.glsl>\n"
    "uniform mat4    mvp;\n"
    "#include <shaders/include/B.glsl>";


int main(int, char**)
{
    std::sregex_iterator        it(s.begin(), s.end(), INCLUDE_REGEXP);
    std::sregex_iterator const    end;
    if (it == end)
    {
        std::printf("Not found\n");
    }
    else
    {
        while (it != end)
        {
            std::printf("Found '%s [%s]'\n", it->str().c_str(),
it->str(1).c_str());
            ++it;
        }
    }
}


When run, this produces:

Found '#include <A.glsl> [A.glsl]'
Found '#include <DontFindThisOne.glsl> [DontFindThisOne.glsl]'
Found '#include <shaders/include/B.glsl> [shaders/include/B.glsl]'

"DontFindThisOne" is found, even though there are "//" between the beginning of
the line and the "#include".

Turning the predicate into a normal capture (full regexp:
"(^|[\n\r])#include\s*<([^>]+)>") results in the desired result (modulo one
additional capture and thus slightly incorrect output).

Removing the begin-of-line atom (full regexp: "(?=[\n\r])#include\s*<([^>]+)>")
results in no finding at all, even though the last line of <s> should be found.

C.f. the thread starting at
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-March/014221.html

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list