1 Commits

Author SHA1 Message Date
Colby Mchenry c19f0284f8 fix(cpp): a declaration inside a string literal is not a receiver's declaration (#2531)
C++ receiver inference reads back from a call for a line that declares
the receiver, blanking comments (cppCodeOf) but not string literals. Text
inside one was taken for the declaration:

- protobuf's upb generator emits C code from raw strings:
  `GenerateRepeatedSetters(upb::FieldDefPtr field, …)` writes
  `upb_MiniTableField field = $field_init$;` inside an `R"cc( … )cc"`,
  then calls `field.ctype()` on its own parameter. The scan found the
  template's line first, and the call got no edge (a C struct has no
  methods).
- rocksdb's log messages read as declarations: `"… in WriteBatch handler;
  …"` made `handler` a `WriteBatch`, and `"… remote compaction (…"` gave
  `compaction` the type `remote`, so calls fell to guesses by the method's
  name.

New cpp-raw-strings.ts reads a file once, when it holds `R"`, as the
compiler does (comments, string and character literals, raw strings with
their delimiters), and keeps the column ranges each raw string takes per
line. The receiver scan, in the file and its header, blanks those and the
contents of the line's ordinary string and character literals before
cppCodeOf. A character literal holding a quote (`'"'`), a digit separator
(`1'000`) and an `R"(` inside a comment don't hide the code after them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 22:17:33 +00:00