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

Tomasz KamiƄski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 23 09:44:13 PDT 2023


tomasz-kaminski-sonarsource added a comment.

>> Indeed, this would address our concern, and allow properly inserting initializer. This would build down to repeating the condition from here: https://github.com/llvm/llvm-project/blob/bbe1394c9602ab9a939d9b17199d5f538cac9d0c/clang/lib/AST/Decl.cpp#L1207.
>>
>> I was suggesting adding an additional function, as it would cover additional use cases like replacing or removing the initializer, and then `VarDecl::getSourceRange` could be defined as:
>>
>>   SourceRange VarDecl::getSourceRange() const {
>>     if (const Expr *Init = getInit()) {
>>       SourceLocation InitEnd = Init->getEndLoc();
>>       // If Init is implicit, ignore its source range and fallback on
>>       // DeclaratorDecl::getSourceRange() to handle postfix elements.
>>       if (InitEnd.isValid() && InitEnd != getLocation())
>>         return SourceRange(getOuterLocStart(), InitEnd);
>>     }
>>     return getDeclatorRange();
>>   }
>
> That would make sense to me.  Feel free to submit a patch (assuming @v1nh1shungry doesn't respond/get to it first).

I https://reviews.llvm.org/D146733 I have submitted a smaller patch, that addresses the regression and the concern. Unfortunately, at this time I am not able to commit to the introduction of the additional method, and its proper handling for AST nodes.


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