Skip to content

[C++] Indent preprocessor directives #43796

@kou

Description

@kou

Describe the enhancement requested

We don't indent in preprocessor directives now. For example:

#if defined(_WIN32) || defined(__CYGWIN__)
// Windows
#if defined(_MSC_VER)
#pragma warning(disable : 4251)
#else
#pragma GCC diagnostic ignored "-Wattributes"
#endif

If we indent preprocessor directives, it improves readability:

#if defined(_WIN32) || defined(__CYGWIN__)
// Windows

#  if defined(_MSC_VER)
#    pragma warning(disable : 4251)
#  else
#    pragma GCC diagnostic ignored "-Wattributes"
#  endif

FYI: Google C++ style guide doesn't require indent in preprocessor directives nor deny it:

https://google.github.io/styleguide/cppguide.html#Preprocessor_Directives

// Good - directives at beginning of line
  if (lopsided_score) {
#if DISASTER_PENDING      // Correct -- Starts at beginning of line
    DropEverything();
# if NOTIFY               // OK but not required -- Spaces after #
    NotifyClient();
# endif
#endif
    BackToNormal();
  }

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions