malcolm.parsons added inline comments.

================
Comment at: test/clang-tidy/cppcoreguidelines-one-name-per-declaration.cpp:8
+  {
+    int x = 42, y = 43;
+    // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Do not declare multiple names 
per declaration [cppcoreguidelines-one-name-per-declaration]
----------------
omtcyfz wrote:
> malcolm.parsons wrote:
> > The guideline says "Flag non-function arguments with multiple declarators 
> > involving declarator operators (e.g., int* p, q;)".
> > 
> > There are no declarator operators in this test, so there should be no 
> > warning.
> The guideline says
> 
> > Reason: One-declaration-per line increases readability and avoids mistakes 
> > related to the C/C++ grammar. It also leaves room for a more descriptive 
> > end-of-line comment.
> 
> > Exception: a function declaration can contain several function argument 
> > declarations.
> 
> I'm not sure why what you copied is written in "Enforcement" section, but I 
> do not think that is how it should be handled. I am concerned not only about 
> that specific case and I see no reason to cut off cases already presented in 
> this test.
"mistakes related to the C/C++ grammar" only occur when declarator operators 
are involved. e.g. in `int* p, q` a reader might incorrectly think that q was a 
pointer.

I see reasons not to warn about cases like
`for (auto i = c.begin(), e = someExpensiveFn(); i != e; i++)`
`for (int i = 0, j = someExpensiveFn(); i < j; i++);`
because the alternatives increase variable scope, or for
`int x = 42, y = 43;`
because it's not difficult to read.

As we disagree on this, can it be made configurable?


https://reviews.llvm.org/D25024



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to