'GNU indent: does it support C++

I used indent to format my C code and it works very well.

Now I'm working with C++ and I still want to use indent. However, I find that it does not support the class declaration very well. Here is an example:

class Test
{
public:
    Test ();
    void ttt ();
protected:
    virtual void func ();
};

This is a header file named test.h and after using indent like this: export VERSION_CONTROL=never; indent -bli0 -blf -bls -nbfda -npsl -i4 -ts4 test.h, it becomes as below:

class Test
{
  public:
        Test ();
        void ttt ();
  protected:
          virtual void func ();
};

As you see, before public and protected, two spaces are added and virtual vodi func(); isn't aligned at all.

So indent doesn't support C++?



Solution 1:[1]

GNU indent offers very limited support for C++ code,

but clang-format will support C++ and other langauges/code like C/Java/JavaScript/JSON/Objective-C/Protobuf/C#.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 winterr_dog