[cfe-dev] [clang-format] Indentation of preprocessor directives

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 30 13:36:31 PDT 2016


Two common styles I come across are whitespace indentation after the ‘#’ but before the pre-processing directive:

 

#if 0

# define A

#endif

 

and whitespace indentation preceding the ‘#’ prefixed pre-processing directive:

 

#if 0

#define A

#endif

 

Can this rule handle both styles, or do you plan on supporting both styles?  I’m not specifically in support of one style versus the other, but I strongly support the idea of a tool that can normalise styles to some given convention, and the more flexibility the better.  And of course no indentation at all:

 

#if 0

#define A

#endif

 

which you already handle.

 

Thanks,

 

            MartinO

 

From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Curdeius Curdeius via cfe-dev
Sent: 30 August 2016 15:49
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] [clang-format] Indentation of preprocessor directives

 

Hi all,

 

I've written a working draft for a new clang-format option "PPDirectiveIndentation" (available at https://github.com/mkurdej/clang/tree/indent-pp-directives).

Basically, it indents preprocessor directives. So, the code

 

#if 0

#define A

#endif

 

becomes

 

#if 0

#   define A

#endif

 

when PPDirectiveIndentation = All.

 

So far, there are only two options (None, All), but I foresee another option Inner or something like that to mimic the behaviour of NamespaceIndentation.

The number of spaces between '#' and the directive name is controlled by IndentWidth option (to be consistent with indentation inside namespaces, classes, blocks etc.), but it may be easily modified.

 

What's the interest in it? Among well known source code that indents preprocessor directives, there are many Boost libraries (a quick search shows e.g. https://github.com/boostorg/asio/blob/develop/include/boost/asio/buffer.hpp).

What are the chances that it gets merged?

 

I'll submit the code for revision to Phabricator this week when I find some more time.

 

Best regards,

Marek

-- 

Marek

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160830/f85b010a/attachment-0001.html>


More information about the cfe-dev mailing list