[PATCH] D23265: [clang-tidy] enhance readability-else-after-return

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 11:01:53 PDT 2016


aaron.ballman added inline comments.

================
Comment at: clang-tidy/readability/ElseAfterReturnCheck.cpp:45
@@ +44,3 @@
+  for (const auto &BindingName :
+       {"return", "continue", "break", "goto", "throw"}) {
+    if (Result.Nodes.getNodeAs<Stmt>(BindingName)) {
----------------
omtcyfz wrote:
> aaron.ballman wrote:
> > omtcyfz wrote:
> > > alexfh wrote:
> > > > This won't work in MSVC2013, I think. Just add a `const char *Labels[] = {"return", ...` (add more consts, constexprs or statics, if you like ;)
> > > Hm, I'm confused. What exactly wouldn't work in MSVC?
> > This one *will* work in MSVC 2013 (it was a different initializer list that @alexfh was thinking of, perhaps, where the deduced type of the list was a bit more complex). I just tried it out and the above construct compiles fine with MSVC.
> > 
> > That being said, `const auto &` is the wrong type here, it should be `const auto *`.
> Hm, I'm confused. Why should it be a pointer?
> 
> So, when I have something like:
> ```
> std::vector<unsigned> vec = {1, 2, 3};
> for (const auto &x : vec) ...
> ```
> 
> This is right, I guess. Why is that different with init list?
The deduced type for the code as-written is `const char * const &`, which isn't wrong, it's just not particularly useful. If you switch to `const auto *`, the deduced type is the much more reasonable `const char *`.


https://reviews.llvm.org/D23265





More information about the cfe-commits mailing list