Skip to content

clang-format SpaceBeforeParens: Always is not always always #55292

@urnathan

Description

@urnathan

clang-format doesn't always seem to format a space between 'identifier (...' when the docs suggest it should:

Here's an input that I have purposefully spaced at odds with clang-format's behaviour -- it is explicitly inserting spaces as expected, or removing them as unexpected.

#define M() 1
#if M () && defined (X) && __has_include ("bob") && __has_cpp_attribute (Y)
#define F(...) __VA_OPT__(__VA_ARGS__)
#endif
void f(){return F(__builtin_LINE () + __builtin_FOO());}
zathras:49> clang-format --style='{BasedOnStyle: LLVM, SpaceBeforeParens: Always}' fmt.cc
#define M() 1
#if M() && defined(X) && __has_include("bob") && __has_cpp_attribute(Y)
#define F(...) __VA_OPT__ (__VA_ARGS__)
#endif
void f () { return F (__builtin_LINE() + __builtin_FOO ()); }
  1. That #if line doesn't insert a space after any of the function-like macro-ish invocations.
  2. The __VA_OPT__ ( invocation does (as expected)
  3. Known builtin __builtin_LINE() has no space, but a random __builtin_FOO () does

The same behaviour with BasedOnStyle: GNU, which of course expects the space in these places.

I'd expect a space in all these cases.

(There is no space in the function-like macro definitions, of course)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions