[llvm-bugs] [Bug 48653] New: clang-format IndentPPDirectives shouldn't always indent pp directives

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 4 09:12:56 PST 2021


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

            Bug ID: 48653
           Summary: clang-format IndentPPDirectives shouldn't always
                    indent pp directives
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: barry.revzin at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

The motivation for having IndentPPDirectives is to be able to take code like:

#if this
#if that
#define other
#endif
#endif

And layer it in a way that's actually readable (space before or after hash
based on user preference):

#if this
#    if that
#        define other
#    endif
#endif

But it doesn't really seem to apply as much to use of preprocessor directives
that aren't all contiguous like that. For instance, we have the following
example (which gets indented as shown):

#ifdef __cpp_deduction_guides
template <typename R, typename... Args>
function_ref(R (*)(Args...)) -> function_ref<R(Args...)>;

#    ifdef __cpp_noexcept_function_type
template <typename R, typename... Args>
function_ref(R (*)(Args...) noexcept) -> function_ref<R(Args...)>;
#    endif
#endif


This is a weird intermediate layer of formatting. It seems like either nothing
should be indented here (i.e. don't indent preprocessor directives if they
follow code):

#ifdef __cpp_deduction_guides
template <typename R, typename... Args>
function_ref(R (*)(Args...)) -> function_ref<R(Args...)>;

#ifdef __cpp_noexcept_function_type
template <typename R, typename... Args>
function_ref(R (*)(Args...) noexcept) -> function_ref<R(Args...)>;
#endif
#endif

Or everything should be indented (i.e. a preprocessor #if is just as much
indent-worthy as a language if):

#ifdef __cpp_deduction_guides
    template <typename R, typename... Args>
    function_ref(R (*)(Args...)) -> function_ref<R(Args...)>;

#   ifdef __cpp_noexcept_function_type
        template <typename R, typename... Args>
        function_ref(R (*)(Args...) noexcept) -> function_ref<R(Args...)>;
#   endif
#endif

I can't say which is better, but either seems better than status quo

-- 
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/20210104/f37652d0/attachment.html>


More information about the llvm-bugs mailing list