[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-27 Thread Tomasz Kamiński via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa826b9034bbd: [clang] source range of variable template 
specialization should include… (authored by tomasz-kaminski-sonarsource).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -230,6 +230,11 @@
   antecipation of `CWG2563 _`.
 - Fix highlighting issue with ``_Complex`` and initialization list with more than
   2 items. (`#61518 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

In D146733#4219448 , @erichkeane 
wrote:

> LGTM!  Let me know if you need someone to commit this for you, and include 
> "Name To Use "

I have commit rights, but I will not be able to commit this before Monday. 
I someone would like to commit these two patches, which I would appreciate, 
please use "Tomasz Kamiński ".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508105.
tomasz-kaminski-sonarsource added a comment.

Rebasing on test commit. My applogies for noise, I still get confused with arc 
sometimes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -230,6 +230,11 @@
   antecipation of `CWG2563 _`.
 - Fix highlighting issue with ``_Complex`` and initialization list with more than
   2 items. (`#61518 `_)
+- Fix  ``getSourceRange`` on  

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

LGTM!  Let me know if you need someone to commit this for you, and include 
"Name To Use "


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508081.
tomasz-kaminski-sonarsource added a comment.

Updated release note to be more descriptive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,11 @@
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 _`.
+- Fix  ``getSourceRange`` on  ``VarTemplateSpecializationDecl`` and
+  ``VarTemplatePartialSpecializationDecl``, which represents 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:228
   antecipation of `CWG2563 
_`.
+- Fix  ``getSourceRange`` behavior on  ``VarTemplateSpecializationDecl``
+  and ``VarTemplatePartialSpecializationDecl``, that represents variable with 
initializer.

Needs a little more detail here.  Something about what was wrong before, and 
what is wrong now, particularly since there is no github bug to link to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508077.
tomasz-kaminski-sonarsource added a comment.

Including release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 _`.
+- Fix  ``getSourceRange`` behavior on  ``VarTemplateSpecializationDecl``
+  and ``VarTemplatePartialSpecializationDecl``, that represents variable with 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Test looks fine, still need a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 507975.
tomasz-kaminski-sonarsource added a comment.

Adding tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp


Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -196,8 +196,7 @@
 
 template<>
 float unTempl = 1;
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

@@ -242,8 +241,7 @@
 
 template<>
 float binTempl = 1;
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 
//===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 
//===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),


Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -196,8 +196,7 @@
 
 template<>
 float unTempl = 1;
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -242,8 +241,7 @@
 
 template<>
 float binTempl = 1;
-// 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

I have updated the description and implementation. Will look at adding a unit 
test tomorrow.




Comment at: clang/lib/AST/DeclTemplate.cpp:1467
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();

erichkeane wrote:
> Looking closer... VarDecl already includes its init in its source range, 
> right?  So perhaps all that needs to happen here is to have the 
> `isExplicitSpecialization` check be :
> 
> `isExplicitSpecialization() && !hasInit()`
> 
> WDYT?
Great suggestion. I really disliked the repetition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 507784.
tomasz-kaminski-sonarsource edited the summary of this revision.
tomasz-kaminski-sonarsource added a comment.

Simpified condition


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 
//===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 
//===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Just noticed your commit-notice reference to the 'breaking' change is 
incorrect, should be: 
https://reviews.llvm.org/D139705

As for the test, an AST-Dump test has the line/column info in it, so that 
should be a good enough test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

In D146733#4216931 , @erichkeane 
wrote:

> This needs a test and a release note.  Patch otherwise looks fine to me.

Do you have any pointers for a test of source ranges? The patch that caused 
regression used a fix-it hit, however, it is not useful in this case, as not 
fixes are raised in the case when the initializer is present.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/DeclTemplate.cpp:1467
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();

Looking closer... VarDecl already includes its init in its source range, right? 
 So perhaps all that needs to happen here is to have the 
`isExplicitSpecialization` check be :

`isExplicitSpecialization() && !hasInit()`

WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 507776.
tomasz-kaminski-sonarsource added a comment.

Comments no longer misleading reffer to fallback to DeclatorDecl


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,21 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();
+// If Init is implicit, ignore its source range
+if (InitEnd.isValid() && InitEnd != getLocation())
+  return SourceRange(getOuterLocStart(), InitEnd);
+  }
+  if (isExplicitSpecialization()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 
//===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 
//===--===//
@@ -1447,6 +1462,20 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();
+// If Init is implicit, ignore its source range
+if (InitEnd.isValid() && InitEnd != getLocation())
+  return SourceRange(getOuterLocStart(), InitEnd);
+  }
+  if (isExplicitSpecialization()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,21 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();
+// If Init is implicit, ignore its source range
+if (InitEnd.isValid() && InitEnd != getLocation())
+  return SourceRange(getOuterLocStart(), InitEnd);
+  }
+  if (isExplicitSpecialization()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1462,20 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (const Expr *Init = getInit()) {
+SourceLocation InitEnd = Init->getEndLoc();
+// If Init is implicit, ignore its source range
+if (InitEnd.isValid() && InitEnd != 

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This needs a test and a release note.  Patch otherwise looks fine to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-23 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource created this revision.
Herald added a project: All.
tomasz-kaminski-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adjust the getSourceRange() for the
VarTemplateSpecializationDecl and VarTemplatePartialSpecializationDecl,
such that the initializer is included if present:

  template
  T temp = 1;
  
  template<> double temp = 1;

This patch makes it consistent with the behavior of
non-template variables with initializes and restores
behavior that was present before https://reviews.llvm.org/D13970.

w!In case, when the initializer is not present we still
include the template-arguments in the source range,
which was required for fixing zero-initialization fix-it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146733

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,22 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::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);
+  }
+  if (isExplicitSpecialization()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 
//===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 
//===--===//
@@ -1447,6 +1463,21 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::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);
+  }
+  if (isExplicitSpecialization()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext , DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID ) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),


Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,22 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::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);
+  }
+  if