[llvm-bugs] [Bug 28998] New: wrong comment parsing with regex

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 16 03:01:23 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28998

            Bug ID: 28998
           Summary: wrong comment parsing with regex
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bremende55 at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The compiler misinterprets/ignores the commented out block (see **** lines) and
produces error messages: (C++14 and C++17)

#include <iostream>
#include <regex>
#include <string>

int main() {
  std::string astring("// x /*  meaningless comment start  ");
  /* comment results in errors  ****
  std::string result = std::regex_replace(
                    astring, std::regex("//[^\n]*/\\*"),  "ZZ ");
  std::cout << "result = " << result << '\n';
  // expected: ZZ   meaningless comment start
  */ // end of comment ****
  std::cout << "astring = " << astring << '\n';
}

If you delete completely the ****-marked lines, the program compiles and gives
the expected result.  clang++ -v gives:
clang version 4.0.0 (trunk 278673)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/4.8
Found candidate GCC installation:
/usr/local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0
Found candidate GCC installation:
/usr/local/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.0
Selected GCC installation:
/usr/local/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.1.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160816/bb6db1cb/attachment.html>


More information about the llvm-bugs mailing list