[PATCH] D13640: [clang-tidy] Add new check cppcoreguidelines-pro-bounds-array-to-pointer-decay

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 13:28:31 PDT 2015


mgehre marked an inline comment as done.

================
Comment at: test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp:13
@@ +12,3 @@
+
+void pointerfun(int* p);
+void arrayfun(int p[]);
----------------
aaron.ballman wrote:
> > Currently, the diag is
> > ```
> > diag(MatchedCast->getExprLoc(), "do not (implicitly) convert an array to a pointer");
> > ```
> > should I make the parenthesis conditional?
> 
> The core guideline only says to diagnose for implicit decay, so I think we should not diagnose in this case.
> 
> Perhaps the wording could be, "do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit decay instead"?
I posted the question here https://github.com/isocpp/CppCoreGuidelines/issues/352
>From my understanding, explicit casts should also be forbidden for the same reasons that implicit decay was:
"Pointers are not arrays". If you need a pointer to the first element of an array, one can still use &a[0].


http://reviews.llvm.org/D13640





More information about the cfe-commits mailing list