Skip to content

Return an empty string instead of asserting in clang-repl toString - #1170

Open
manpreetsinghraina191-rgb wants to merge 1 commit into
compiler-research:mainfrom
manpreetsinghraina191-rgb:fix-1100-objtostring
Open

manpreetsinghraina191-rgb wants to merge 1 commit into
compiler-research:mainfrom
manpreetsinghraina191-rgb:fix-1100-objtostring

Conversation

@manpreetsinghraina191-rgb

Copy link
Copy Markdown

Fixes #1100.

Interpreter::toString on the clang-repl path was an assert(0) stub, so Cpp::ObjToString aborted when assertions were enabled and silently returned "" when they weren't.

This PR follows the interim approach discussed in the issue: report failure instead of asserting, so callers such as cppjit's op_str can fall back.

  • The clang-repl toString now returns "" in every build. A FIXME notes that it should move to clang-repl's value printer once that supports user-defined types; upstream still has FIXME: Add support for user defined printers.
  • ObjToString's docs now state that "" means there is no string representation, which is always the case under clang-repl.
  • Added the Interpreter_ObjToString test. It expects "" under clang-repl and a non-empty string under Cling.

The public signature is unchanged, so existing callers aren't affected.

Open question: should ObjToString eventually return Cpp::Result<std::string>? I left that out because no public API uses Result<T> yet, and it seemed like a call for the error-model work rather than this fix.

Interpreter::toString was an assert(0) stub on the clang-repl path, so
Cpp::ObjToString aborted with assertions enabled and silently returned
"" without them. Return "" in every build and document it as "no string
representation", so callers can fall back instead of crashing.

Fixes compiler-research#1100.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interpreter::toString is an assert(0) stub, so ObjToString aborts or silently returns ""

1 participant