[PATCH] D139705: [clang] fix zero-initialization fix-it for variable template

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 09:48:30 PST 2023


erichkeane added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:3863
 
+  SourceLocation EndLoc = VD->getEndLoc();
+  if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
----------------
v1nh1shungry wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > Hmm... it is strange to me that the variables 'endloc' is the end of the identifier and not the end of the variable declaration.  I unfortunately don't have a good feeling as to the 'correct' behavior for that (Aaron is typically the one who understands source locations better than me!), so hopefully he can come along and see.  
> > I don't think we should have to do this dance here, this is something that `getEndLoc()` should be able to tell us. The way that source locations work is that AST nodes can override `getSourceRange()` to produce the correct range information for the node, and then they expose different accessors for any other source location information. In this case, I think `VarTemplateSpecializationDecl` isn't overloading `getSourceRange()` and so we're getting the default behavior from `VarDecl`.
> Sorry! I'm confused here. Do you mean we should use `getEndLoc()` directly as the location where the fix-hint insert? But isn't the original code using `getEndLoc()`, it turns out to add the fix-hint after the end of the identifier instead of the right angle of `VarTemplateSpecializationDecl`.
Right, we should use `getEndLoc` directly for hte fixit location, and 'fix' `getEndLoc` by having `VarTemplateSpecializationDecl` override `getSourceRange` to have the right `end loc`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139705/new/

https://reviews.llvm.org/D139705



More information about the cfe-commits mailing list