[clang-format] add option -fallback-style=fail (fail if -style=file falls back)

Dear all,

I want to provide information to the clang-format user if the style
is/can be used, or if clang-format sees itself forced to fall back to
the fallback-style. I.e. in contrast to doing nothing, as with
- -fallback-style=none, I want clang-format to fail. Kind of as a reminder
to the user "hey, maybe you forgot to add your .clang-format file to
your project".

I was thinking about doing this through an option
`-fallback-style=fail`. Do you think that is the right approach?

If yes, I gave it a try and wrote the attached one-off patch, which adds
the option `-fallback-style=fail`.

I *briefly* tested it on my system by building `make clang-format`[1] and
tried what happens when no .clang-format file exists and I run
`clang-format -style=file -fallback-style=fail main.cc` on a minimal
hello world c++ file.

NB: the patch does contain an update of the unit test, but I did not
manage to run it (problems with the system I was running on …).

Thanks in advance for feedback,


For reference:
This addresses what I asked on Stackoverflow

and is a duplication of my pull request on github

[1]: when following steps 1-3 from
Clang - Getting Started and then running `make
clang-format` in step 7 instead of `make`.

clang-format-fallback-fail.patch (3.54 KB)