I have problem with finding main include for my source files. But step by step.
File z.h
#include "test"
#include "azd"
#include <vector>
#include <boost/something>
#include <map>
File z.C
#include "test"
#include "azd"
#include <vector>
#include <boost/something>
#include <map>
#include "z.h"
File (part) .clang-format located together with z.h and z.C
BasedOnStyle: LLVM
Language: Cpp
IncludeIsMainRegex: '(_test)?$'
IncludeCategories:
- Regex: '^(<boost)'
Priority: 3
- Regex: '^<'
Priority: 4
- Regex: '.*'
Priority: 1
Now, testing:
$ clang-format z.h
#include "azd"
#include "test"
#include <boost/something>
#include <map>
#include <vector>
Here, everything looks great, includes sorted as expected, but
$ clang-format z.C
#include "azd"
#include "test"
#include "z.h"
#include <boost/something>
#include <map>
#include <vector>
Here, "a.z" is on the middle, although is should be detected by '(_test)?$' as main include. The funny part is that when I rename z.C -> z.cc and then:
$ clang-format z.cc
#include "z.h"
#include "azd"
#include "test"
#include <boost/something>
#include <map>
#include <vector>
works OK...
It seems that clang-format does not recognize *.C files as C++ language. I am working on C++ project where I do not have luxury to rename all *.C files to *.cc, so please can someone tell me how to force clang-format to use C++ style formatting on *.C files? Or to solve this problem with finding main include with another approach?
And second issue/question. We sometime split templates declarations and definitions into template.h and templateImpl.h files. How to force clang-format to treat templateImpl.h as source and put #include "template.h" as main include?
Regards