https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/129116

>From ed0cf3f026e439288f8334f27555ad26825fd56a Mon Sep 17 00:00:00 2001
From: AmrDeveloper <am...@programmer.net>
Date: Thu, 27 Feb 2025 21:49:32 +0100
Subject: [PATCH 1/4] [Clang][diagnostics] Fix structured binding shadows
 template parameter location

---
 clang/lib/Sema/SemaDeclCXX.cpp                 | 3 +--
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 5 +++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 664d48ccbc382..a3a028b9485d6 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -883,8 +883,7 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
     // It's not permitted to shadow a template parameter name.
     if (Previous.isSingleResult() &&
         Previous.getFoundDecl()->isTemplateParameter()) {
-      DiagnoseTemplateParameterShadow(D.getIdentifierLoc(),
-                                      Previous.getFoundDecl());
+      DiagnoseTemplateParameterShadow(B.NameLoc, Previous.getFoundDecl());
       Previous.clear();
     }
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index 00bb35813c39a..e464bb5e7eaef 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -162,3 +162,8 @@ struct A {
 };
 A<0>::B a;
 }
+
+template <typename T> void shadow9() {  // expected-note{{template parameter 
is declared here}}
+  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+}

>From 7712fc1c2406974d64e6fa8c162d12b6090903f2 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <am...@programmer.net>
Date: Fri, 28 Feb 2025 18:43:54 +0100
Subject: [PATCH 2/4] Add release note and improve testing

---
 clang/docs/ReleaseNotes.rst                    | 2 ++
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b72143482943..b1ea63a01b914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
+- Improve the diagnostics for shadows template parameter.
+
 Improvements to Clang's time-trace
 ----------------------------------
 
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index e464bb5e7eaef..aa00e1b8811ec 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -163,7 +163,9 @@ struct A {
 A<0>::B a;
 }
 
-template <typename T> void shadow9() {  // expected-note{{template parameter 
is declared here}}
+template <typename T> void shadow() {  // expected-note{{template parameter is 
declared here}}
   using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
-  auto [T] = arr{}; // expected-error {{declaration of 'T' shadows template 
parameter}}
+  auto [
+    T // expected-error {{declaration of 'T' shadows template parameter}}
+    ] = arr{};
 }

>From 780a3b259283834e72dccd1ac34cbeafb0a301d9 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <am...@programmer.net>
Date: Fri, 28 Feb 2025 19:38:21 +0100
Subject: [PATCH 3/4] Address code review comments

---
 clang/docs/ReleaseNotes.rst                    | 2 +-
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b1ea63a01b914..6c9eacbb0751d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,7 +214,7 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
-- Improve the diagnostics for shadows template parameter.
+- Improve the diagnostics for shadows template parameter to report correct 
location (#GH129060).
 
 Improvements to Clang's time-trace
 ----------------------------------
diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index aa00e1b8811ec..ee23bf103d450 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -164,7 +164,8 @@ A<0>::B a;
 }
 
 template <typename T> void shadow() {  // expected-note{{template parameter is 
declared here}}
-  using arr = int[1]; // expected-warning@+1 {{decomposition declarations are 
a C++17 extension}}
+  using arr = int[1];
+  // expected-warning@+1 {{decomposition declarations are a C++17 extension}}
   auto [
     T // expected-error {{declaration of 'T' shadows template parameter}}
     ] = arr{};

>From 7670ec80ec816a87987026e5639e2bd3f29d1a3f Mon Sep 17 00:00:00 2001
From: AmrDeveloper <am...@programmer.net>
Date: Fri, 28 Feb 2025 20:04:50 +0100
Subject: [PATCH 4/4] Make a call to test function

---
 clang/test/CXX/temp/temp.res/temp.local/p6.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index ee23bf103d450..205df5fa25870 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -163,10 +163,13 @@ struct A {
 A<0>::B a;
 }
 
-template <typename T> void shadow() {  // expected-note{{template parameter is 
declared here}}
+template <typename T> int shadow() {  // expected-note{{template parameter is 
declared here}}
   using arr = int[1];
   // expected-warning@+1 {{decomposition declarations are a C++17 extension}}
   auto [
     T // expected-error {{declaration of 'T' shadows template parameter}}
     ] = arr{};
+  return 0;
 }
+
+auto Use = shadow<int>();

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

Reply via email to