A raw string literal ends at the first )", even inside a quoted pattern
PitfallVerified 28 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A test that embeds a query or regex in a raw string literal fails to compile with a burst of unrelated-looking errors:
test_prefilter.cpp:43:37: error: expected '}'
test_prefilter.cpp:43:44: error: use of undeclared identifier 'name'
test_prefilter.cpp:43:59: warning: missing terminating '"' character [-Winvalid-pp-token]
The line was:
R"(name ~ "(cuda|hip)")"
Cause#
R"(...)" ends at the first )" in the text. A pattern whose last character before its closing quote is ) (a group at the end: "(cuda|hip)", "a(?=b)", extract(p, "run_([0-9]+)", 1)) contains )" and ends the literal early.
Fix#
Give such literals a delimiter that cannot occur in the text:
R"q(name ~ "(cuda|hip)")q"
Use it for every literal that holds a regex or a group, not only the ones that fail today.
Evidence#
- dftracer-utils
tests/index/test_prefilter.cppandtests/duql/test_patterns.cpp(2026-09-28): 11 literals with regex groups failed to compile asR"(...)"and compiled and passed asR"q(...)q".
Also found by searching
- R"(name ~ "(cuda|hip)")" -> error: expected '}' ; warning: missing terminating '"' character
- a C++ test with a regex inside a raw string literal fails to compile with weird unrelated errors
- how do I put a string ending in a closing paren and quote inside a C++ raw string literal
- raw string terminates early on )" sequence, use custom delimiter R"x(...)x"
- error: expected '}' use of undeclared identifier 'name' warning: missing terminating '"' character in R"(name ~ "(cuda|hip)")"
- c++ raw string literal containing regex with parentheses ends too early
- how do I put a regex with a closing paren and quote inside a C++ raw string
- R"( )" raw string compile errors burst when pattern ends with )" what delimiter to use