[cfe-dev] [Clang-format] space between closing angles for templates

Suyog Kamal Sarda suyog.sarda at samsung.com
Wed Oct 29 04:39:50 PDT 2014


Hi Daniel,

Had few questions related to space between closing angles for templates.

Test code : vector<vector<int> > matrix(RR); (there is a space between the two closing angles).

When I run clang-format on this, it uses LLVM style by default and eliminates space between the two angles.
After formatting : vector<vector<int>> matrix(RR);  

When I try to compile the code, I get the error 
"a space is required between consecutive right angle brackets".

When I compile the formatted code with -std=c++11 option, it compiles without error.
The new standard accepts closing angles without spaces while older needs space between the two.

With other styles - Google, Chromium, Mozilla, Webkit - clang-format doesn't remove the space between 
the angles. Google and Chromium style accepts both the format, Webkit and Mozilla inserts space if not present.

Does LLVM style by default follow c++11 standard? 
( I saw both '> >' and '>>' in LLVM code. )

Should the default style (which is LLVM) remove the space or should it accept both cases?

Shouldn't the error string "a space is required between consecutive right angle brackets" also 
include mention about c++11 standard? Something like 'allowed in c++11 onwards' to make things 
more clear? 

Because running clang-format with default style on code with space separate angles
and then compiling without -std=c++11 option throws error which is somewhat confusing. 

I tried changing the code the in TokenAnnotator.cpp file in function 'calculateFormattingInformation' 
where I keep track of number of TemplateCloser, and if the number > 1 then set the SpaceRequiredBefore
to 1. However this was breaking several test cases, mostly related to specific styles.

Regards,
Suyog




More information about the cfe-dev mailing list