[llvm-bugs] [Bug 39163] New: Extend IndentPPDirectives with a LeaveAsIs option

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 3 08:29:38 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39163

            Bug ID: 39163
           Summary: Extend IndentPPDirectives with a LeaveAsIs option
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: niklas.frykholm at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Currently IndentPPDirectives can have values None or AfterHash. There has
also been a suggestion of a BeforeHash option.

I suggest adding another option Leave, which would leave preprocessor
directives alone (i.e. not change the indentation at all).

Motivation:

    Indenting pre-processor directives can be really tricky with lots of
    edge cases. There maybe certain directives you do not want indented,
    for example. clang-format already has some detection of include guards
    as I understand it, but we also use platform macros around entire
    files:

    #ifdef OSX
    ...
    #endif

    These are not recognized and cause the entire file to be indented.

    Further complications arise from interaction between macros and C
    code, when you want macros to be indented to the scope of the C code
    and the C code to be indented to the scope of the macros, i.e.:

    if (x) {
        #ifdef OSX
           bla();
        #endif
    }

    While it is possible to come up with decent indentation for simple
    cases like this, it can get hairy, since the macros don't follow the
    C syntax and vice versa. For example, the scopes in C code and the
    preprocessor don't have to nest nicely. It may be hard to come up with
    good consistent rules for how C/preprocessor interactions should be
    handled.

    A Leave option would sidestep these thorny issues and leave the
    indentation of preprocessor macros to the code author. It should also
    be easy to implement.

References:

* https://bugs.llvm.org/show_bug.cgi?id=17362
* https://bugs.llvm.org/show_bug.cgi?id=36019
* https://bugs.llvm.org/show_bug.cgi?id=36020

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181003/b1d516fb/attachment.html>


More information about the llvm-bugs mailing list