Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a .clang-format file #27

Open
db-tech opened this issue Jun 6, 2021 · 2 comments
Open

Creating a .clang-format file #27

db-tech opened this issue Jun 6, 2021 · 2 comments
Labels
dev Developing uvgRTP is easier, but these features are not visible to users of the library

Comments

@db-tech
Copy link

db-tech commented Jun 6, 2021

As I was working an the other Issues, i thought it would be nice to have a .clang-format file.
Nowadays, that is almost the first thing I do in a new project.
I tried to create a .clang-format file that exactly matches the current style but hit a problem.
It is currently not possible to indent the class access modifier as it's own entity.
So, something like this cannot be done (at the moment, clang < version 12):

class A {
    public:
        int do_something();
        
};

What could be done is to indent the function definition with 4 spaces and offset the access modifier with 1 or two:

class A {
  public:
    int do_something();
        
};

I honestly would prefer it that way because I think the four spaces here (8 spaces from class to function definition) is a little to much. But because that changes the style you chose, I would understand that you disagree!

There is a good explanation of that problem here: https://stackoverflow.com/questions/29198963/how-can-i-tell-clang-format-to-indent-visibility-modifiers

Any thoughts ?

@altonen
Copy link
Collaborator

altonen commented Jun 6, 2021

Hi,

I obviously prefer the style that I chose but if it cannot be done with clang-format then it can be changed. It seem that I misunderstood something you wrote, because the link you provided shows that custom indentation can be given to access modifiers. Can you explain what you meant by "not possible to indent the class access modifier as it's own entity"?

@db-tech
Copy link
Author

db-tech commented Jun 6, 2021

Yeah sorry, my English isn't that good :-/

I meant that class modifiers like "public:", "private:" and "protected:" have no identation option in the config file.
So if we set IndentWidth to 4 the class will just look like this:

class A {
    void defaultPrivateFunction();

    public:
    int do_something();
        
};

So everything will have 4 spaces, "public:" will not add anything to this.

We then could add an offset to the modifier AccessModifierOffset: -2, then it will look like this:

class A {
    void defaultPrivateFunction();

  public:
    int do_something();
        
};

So "public:" will move 2 spaces to the left.

I hope that was understandable.

This seems to be changed in Clang Version 12, there they added an option called: IndentAccessModifiers: true.
But I am not sure when this will be released or if this option will stay.

@jrsnen jrsnen added the feature New feature label Jun 16, 2021
@jrsnen jrsnen added dev Developing uvgRTP is easier, but these features are not visible to users of the library and removed feature New feature labels Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Developing uvgRTP is easier, but these features are not visible to users of the library
Projects
None yet
Development

No branches or pull requests

3 participants