Filter out comments in Delphi source code
I only have a few minor comments.
The first is about your empty while loops, such as:
    for (i = sbuf-&gt;sbumpc(); i == '{'; i = sbuf-&gt;sbumpc()) {
        while ((i = sbuf-&gt;sbumpc()) != '}');
    }

I generally prefer to at least put the semicolon on a line by itself, to make it fairly obvious that it's intentional that the semicolon wasn't just accidentally entered at the end of a line where it shouldn't have been:
for (i = sbuf-&gt;sbumpc(); i == '{'; i = sbuf-&gt;sbumpc()) {
    while ((i = sbuf-&gt;sbumpc()) != '}')
        ;
}

In this case, there's no other statement there before the closing brace that the loop could be controlling so it's probably less serious than usual, but I still prefer consistency (even though: &quot;a foolish consistency is the hobgoblin of small minds&quot;).
Second, if you're going to do all this, I'd probably add a little commentfilterstream class on this order:
#include &lt;fstream&gt;
#include &lt;istream&gt;

class commentfilterstream : public std::istream {
    std::filebuf buffer;
    commentfilterbuf buf;

public:
    // or use an `std::filesystem::path` instead of a string.
    commentfilterstream(std::string const&amp; filename)
        : buf(&amp;buffer)
        , std::istream(&amp;buf)
    {
        buffer.open(filename.c_str(), std::ios_base::in);
    }

    ~commentfilterstream() { buffer.close(); }
};

This lets you simplify the client code a bit to become something like this:
int main(int argc, char* argv[])
{
    if (argc != 2) {
        std::cerr &lt;&lt; &quot;Usage: testfilter inputfile\n&quot;;
        return 0;
    }

    // Opening stream is now one step, just like usual:
    commentfilterstream in{argv[1]};

    if (!fin) {
        std::cerr &lt;&lt; &quot;Error: could not open &quot; &lt;&lt; argv[1] &lt;&lt; &quot;\n&quot;;
        return 1;
    }

    std::string line;
    for (std::string line; std::getline(in, line); ) {
        std::cout &lt;&lt; line &lt;&lt; '\n';
    }
}

Finally, I'd probably put the buffer and filter into a namespace (e.g., Delphi) to give a little better indication of their intended purpose (Delphi::commentfilterstream).