I have a cpp code like :
#include<bits/stdc++.h>
using namespace std;
namespace a {
const int b=1;
}
int main() {
cout << "hello" << endl;
return 0;
}
I tried the following configuration of .clang-format
Language: Cpp
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterStruct: true
BeforeCatch: false
BeforeElse: false
FixNamespaceComments: true # add commend at end:
NamespaceIndentation: All #intend content of namespace
Expected output includes a comment at end of namespace closing bracket // namespace a
.
but it is not shown if there is only int a in namespace.
When I tried putting one more variable in namespace it worked fine.
I am using clang-format-6.0
It's been hardcoded in clang-format that namespace end comments aren't added to namespaces with only 1 line which seems quite arbitrary because there's not much difference between a namespace with 1 or 2 or 3 statements.
The offending code:
// The maximal number of unwrapped lines that a short namespace spans.
// Short namespaces don't need an end comment.
static const int kShortNamespaceMaxLines = 1;
https://github.com/llvm-mirror/clang/blob/release_70/lib/Format/NamespaceEndCommentsFixer.cpp
Clang-Format will not add namespace end comment for "short" namespaces, i.e. namespaces that contain very few lines of code. Default is to not add the comment for namespaces of one line. The number of lines is configurable, see https://clang.llvm.org/docs/ClangFormatStyleOptions.html#shortnamespacelines. Setting the option to 0 should add namespace end comment to all namespaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With