Menu

#382 nested #if within a function not properly indented

wont-fix
None
2016-10-27
2015-11-30
Soukyuu
No

I'm trying to make AStyle keep/create the following indentation:

void funcA()
{
   #if SomeDefine >= 1
      SOMEMACRO1(param1, param2)
      #if someDefine >= 2
         SOMEMACRO2(param1, param2)
         #if someDefine >= 3
            SOMEMACRO3(param1, param2)
         #endif
      #endif
   #endif
}

However, it keeps removing all indentation ending up with

void funcA()
{
   #if SomeDefine >= 1
   SOMEMACRO1(param1, param2)
   #if someDefine >= 2
   SOMEMACRO2(param1, param2)
   #if someDefine >= 3
   SOMEMACRO3(param1, param2)
   #endif
   #endif
   #endif
}

The same code block outside a function works correctly. I'm currently using this command line:

AStyle.exe "*.cpp" "*.h" -r --mode=c --max-instatement-indent=60 --indent=spaces=3 --align-reference=name --align-pointer=name --indent-classes --indent-switches --indent-namespaces --indent-preproc-block --indent-preproc-define --indent-preproc-cond --pad-oper --unpad-paren --break-closing-brackets --add-brackets --convert-tabs

I've already tried removing each and all of the prepocessor indent options, but it is still removing the indentation, even though the description of "--indent-preproc-define" says leaving out the option will leave the block unchanged.

The only way to make it work currently seems to be wrapping it into an *INDENT-OFF* *INDENT-ON* block. Not sure if it's a bug or a feature, but it's pretty confusing it works differently inside a function than outside.

Discussion

  • Soukyuu

    Soukyuu - 2015-11-30

    So the "code tags" the editor provided didn't work. Yay. One more try:

    void funcA()
    {
       #if SomeDefine >= 1
          SOMEMACRO1(param1, param2)
          #if someDefine >= 2
             SOMEMACRO2(param1, param2)
             #if someDefine >= 3
                SOMEMACRO3(param1, param2)
             #endif
          #endif
       #endif
    }
    

    However, it keeps removing all indentation ending up with

    void funcA()
    {
       #if SomeDefine >= 1
       SOMEMACRO1(param1, param2)
       #if someDefine >= 2
       SOMEMACRO2(param1, param2)
       #if someDefine >= 3
       SOMEMACRO3(param1, param2)
       #endif
       #endif
       #endif
    }
    
     
  • Soukyuu

    Soukyuu - 2016-08-31

    It's been a while, are there plans to fix this or is the behavior intended?

     
  • Jim Pattee

    Jim Pattee - 2016-09-07

    I had to check the code because I didn't remember what the options did.

    The program was never intended to use the format you wanted. The option with the removed indentation is the way astyle formats preprocessor directives.

    The format outside a function is intended for #ifdef defines and is done different.

    There are no plans to change this.

     
  • Jim Pattee

    Jim Pattee - 2016-09-10
    • status: open --> wont-fix
    • assigned_to: Jim Pattee
    • Priority: 5 --> 7
     
  • Peter

    Peter - 2016-10-17

    If I read the docs correctly, --indent-preproc-block does not work inside methods, presumably means functions. I find it hard to see the design rationale here. I don't want to re-run indent wars but most people would indent the bodies of if-statements inside a function. I cannot see the fundamental difference with preprocessor conditionals except that one is a choice made at run time and the other made at build time. This behaviour seems to be treating them differently.

     
  • Soukyuu

    Soukyuu - 2016-10-27

    What I can't see is the reasoning behind indenting them outside the methods while not indenting them inside the functions - either don't indent at all, or indent both. Else there is an inconsistency introduced by a process that is meant to make code look consistent.

     

Log in to post a comment.

MongoDB Logo MongoDB