[llvm] [llvm-objdump] Fix coloring with nested WithMarkup (PR #113834)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 01:38:22 PDT 2024


================
@@ -226,27 +226,32 @@ format_object<uint64_t> MCInstPrinter::formatHex(uint64_t Value) const {
 
 MCInstPrinter::WithMarkup MCInstPrinter::markup(raw_ostream &OS,
                                                 Markup S) const {
-  return WithMarkup(OS, S, getUseMarkup(), getUseColor());
+  return WithMarkup(const_cast<MCInstPrinter &>(*this), OS, S, getUseMarkup(),
----------------
jh7370 wrote:

Yuck, okay. I think that's probably still the "right" thing to do (after all you're modifying the state of the class when calling these methods in this manner). But I acknowledge that's probably a bit impractical too, so if you add a TODO comment here instead, I'd be happy with that.

I also considered making the `ColorStack` member `mutable`, but that doesn't really feel any better than the `const_cast` in this context.

https://github.com/llvm/llvm-project/pull/113834


More information about the llvm-commits mailing list