Repository: fmtlib/fmt
File: include/fmt/ranges.h (C/C++)

Code before:
        check_for_s = true;
        is_debug = true;
      }
      if (it != end && *it == 's') {
        if (!std::is_same<T, Char>::value) {
          report_error("invalid format specifier");
        }
        if (!is_debug) {
          set_brackets(detail::string_literal<Char, '"'>{},
                       detail::string_literal<Char, '"'>{});
        }
        check_for_s = false;
        is_string_format = true;
        ++it;
      }
      if (check_for_s) {
        report_error("invalid format specifier");
      }
    }

    if (it != end && *it != '}') {
      if (is_string_format || *it != ':')
        report_error("invalid format specifier");
      ++it;
    } else {
      if (!is_string_format) detail::maybe_set_debug_format(underlying_, true);
    }

    ctx.advance_to(it);
    return underlying_.parse(ctx);
  }

  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            enable_if_t<std::is_same<U, Char>::value, bool> = true>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    auto buf = basic_memory_buffer<Char>();
    for (; it != end; ++it) {
      auto&& item = *it;
      buf.push_back(item);
    }
    format_specs spec_str{};
    spec_str.type = presentation_type::debug;
    return detail::write<Char>(
        out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
  }
  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            enable_if_t<!(std::is_same<U, Char>::value), bool> = true>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    detail::ignore_unused(it);
    detail::ignore_unused(end);
    return out;

Review comment (bug):
Similarly, let's get rid of this check by either setting the debug format beforehand or in the default branch of the switch suggested to add in a comment above.

Code after:
    case '?':
      is_debug = true;
      set_brackets({}, {});
      ++it;
      if (it == end || *it != 's') {
        report_error("invalid format specifier");
      }
      FMT_FALLTHROUGH;
    case 's':
      if (!std::is_same<T, Char>::value) {
        report_error("invalid format specifier");
      }
      if (!is_debug) {
        set_brackets(detail::string_literal<Char, '"'>{},
                     detail::string_literal<Char, '"'>{});
        set_separator({});
        detail::maybe_set_debug_format(underlying_, false);
      }
      is_string_format = true;
      ++it;
      return it;
    }

    if (it != end && *it != '}') {
      if (*it != ':') report_error("invalid format specifier");
      detail::maybe_set_debug_format(underlying_, false);
      ++it;
    }

    ctx.advance_to(it);
    return underlying_.parse(ctx);
  }

  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            FMT_ENABLE_IF(std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    auto buf = basic_memory_buffer<Char>();
    for (; it != end; ++it) {
      buf.push_back(*it);
    }
    format_specs spec_str;
    spec_str.type = presentation_type::debug;
    return detail::write<Char>(
        out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
  }
  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            FMT_ENABLE_IF(!std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, Iter&, IterEnd&) const -> Output {
    return out;
  }