[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Shafik Yaghmour via cfe-commits


@@ -2061,13 +2070,13 @@ DeclResult Sema::CheckClassTemplate(
   if (!(TUK == TUK_Friend && CurContext->isDependentContext()) &&
   CheckTemplateParameterList(
   TemplateParams,
-  PrevClassTemplate
-  ? PrevClassTemplate->getMostRecentDecl()->getTemplateParameters()
-  : nullptr,
+  PrevClassTemplate ? GetTemplateParameterList(PrevClassTemplate)
+: nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
   ? TPC_ClassTemplateMember
-  : TUK == TUK_Friend ? TPC_FriendClassTemplate : 
TPC_ClassTemplate,
+  : TUK == TUK_Friend ? TPC_FriendClassTemplate

shafik wrote:

This looks like an unrelated change and it looks funny.

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Can we please add more detailed summaries, we want the git log to be sufficient 
for triaging various issues without having to dig into each commit individually.

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Haojian Wu via cfe-commits

https://github.com/hokein closed https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Haojian Wu via cfe-commits

hokein wrote:

Thanks for the review.

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM, thanks

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Haojian Wu via cfe-commits


@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)

hokein wrote:

Done.

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-18 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/75569

>From 0f49d91b4a22944216cff8654f9c00f892bb02be Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 15 Dec 2023 08:44:57 +0100
Subject: [PATCH 1/2] [clang] Fix CTAD not respect default template arguments
 that were added after the definition.

Fixes https://github.com/llvm/llvm-project/issues/69987
---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaTemplate.cpp  | 22 +-
 clang/test/SemaTemplate/ctad.cpp | 10 ++
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5ae6bb8925202..be826e6a44bfc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..450a1a1db0ba86 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1824,6 +1824,15 @@ static void SetNestedNameSpecifier(Sema , TagDecl *T,
 T->setQualifierInfo(SS.getWithLocInContext(S.Context));
 }
 
+// Returns the template parameter list with all default template argument
+// information.
+static TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD) {
+  // Make sure we get the template parameter list from the most
+  // recent declaration, since that is the only one that is guaranteed to
+  // have all the default template argument information.
+  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+}
+
 DeclResult Sema::CheckClassTemplate(
 Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
 CXXScopeSpec , IdentifierInfo *Name, SourceLocation NameLoc,
@@ -2062,7 +2071,7 @@ DeclResult Sema::CheckClassTemplate(
   CheckTemplateParameterList(
   TemplateParams,
   PrevClassTemplate
-  ? PrevClassTemplate->getMostRecentDecl()->getTemplateParameters()
+  ? GetTemplateParameterList(PrevClassTemplate)
   : nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
@@ -2298,7 +2307,7 @@ struct ConvertConstructorToDeductionGuideTransform {
 //-- The template parameters are the template parameters of the class
 //   template followed by the template parameters (including default
 //   template arguments) of the constructor, if any.
-TemplateParameterList *TemplateParams = Template->getTemplateParameters();
+TemplateParameterList *TemplateParams = GetTemplateParameterList(Template);
 if (FTD) {
   TemplateParameterList *InnerParams = FTD->getTemplateParameters();
   SmallVector AllParams;
@@ -2424,7 +2433,7 @@ struct ConvertConstructorToDeductionGuideTransform {
   Params.push_back(NewParam);
 }
 
-return buildDeductionGuide(Template->getTemplateParameters(), nullptr,
+return buildDeductionGuide(GetTemplateParameterList(Template), nullptr,
ExplicitSpecifier(), TSI, Loc, Loc, Loc);
   }
 
@@ -5956,12 +5965,7 @@ bool Sema::CheckTemplateArgumentList(
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  // Make sure we get the template parameter list from the most
-  // recent declaration, since that is the only one that is guaranteed to
-  // have all the default template argument information.
-  TemplateParameterList *Params =
-  cast(Template->getMostRecentDecl())
-  ->getTemplateParameters();
+  TemplateParameterList *Params = GetTemplateParameterList(Template);
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();
 
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 4d836839d8c346..388ed7d4cced18 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -44,3 +44,13 @@ namespace Access {
   };
   D z = {Z(), {}};
 }
+
+namespace GH69987 {
+template struct X {};
+template struct X;
+X x;
+
+template struct Y { Y(T); };
+template struct Y ;
+Y y(1);
+};

>From 87ad4508047f7be623871ca61967d3ff02313fcf Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 18 Dec 2023 10:53:55 +0100
Subject: [PATCH 2/2] Update the release doc and fix clang-format

---
 clang/docs/ReleaseNotes.rst | 3 ++-
 clang/lib/Sema/SemaTemplate.cpp | 8 
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst 

[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-15 Thread Mariya Podchishchaeva via cfe-commits


@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)

Fznamznon wrote:

A little nit to align the style
```suggestion
  are added in a later redeclaration for CTAD.
  Fixes (#69987 `_)
```

https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-15 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff f1ea77f7be8acda2aa4b08ba27f454512a872057 
0f49d91b4a22944216cff8654f9c00f892bb02be -- clang/lib/Sema/SemaTemplate.cpp 
clang/test/SemaTemplate/ctad.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 450a1a1db0..5fcc39ec70 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2070,13 +2070,13 @@ DeclResult Sema::CheckClassTemplate(
   if (!(TUK == TUK_Friend && CurContext->isDependentContext()) &&
   CheckTemplateParameterList(
   TemplateParams,
-  PrevClassTemplate
-  ? GetTemplateParameterList(PrevClassTemplate)
-  : nullptr,
+  PrevClassTemplate ? GetTemplateParameterList(PrevClassTemplate)
+: nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
   ? TPC_ClassTemplateMember
-  : TUK == TUK_Friend ? TPC_FriendClassTemplate : 
TPC_ClassTemplate,
+  : TUK == TUK_Friend ? TPC_FriendClassTemplate
+  : TPC_ClassTemplate,
   SkipBody))
 Invalid = true;
 

``




https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

Fixes https://github.com/llvm/llvm-project/issues/69987

---
Full diff: https://github.com/llvm/llvm-project/pull/75569.diff


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+13-9) 
- (modified) clang/test/SemaTemplate/ctad.cpp (+10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5ae6bb8925202..be826e6a44bfc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..450a1a1db0ba86 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1824,6 +1824,15 @@ static void SetNestedNameSpecifier(Sema , TagDecl *T,
 T->setQualifierInfo(SS.getWithLocInContext(S.Context));
 }
 
+// Returns the template parameter list with all default template argument
+// information.
+static TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD) {
+  // Make sure we get the template parameter list from the most
+  // recent declaration, since that is the only one that is guaranteed to
+  // have all the default template argument information.
+  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+}
+
 DeclResult Sema::CheckClassTemplate(
 Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
 CXXScopeSpec , IdentifierInfo *Name, SourceLocation NameLoc,
@@ -2062,7 +2071,7 @@ DeclResult Sema::CheckClassTemplate(
   CheckTemplateParameterList(
   TemplateParams,
   PrevClassTemplate
-  ? PrevClassTemplate->getMostRecentDecl()->getTemplateParameters()
+  ? GetTemplateParameterList(PrevClassTemplate)
   : nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
@@ -2298,7 +2307,7 @@ struct ConvertConstructorToDeductionGuideTransform {
 //-- The template parameters are the template parameters of the class
 //   template followed by the template parameters (including default
 //   template arguments) of the constructor, if any.
-TemplateParameterList *TemplateParams = Template->getTemplateParameters();
+TemplateParameterList *TemplateParams = GetTemplateParameterList(Template);
 if (FTD) {
   TemplateParameterList *InnerParams = FTD->getTemplateParameters();
   SmallVector AllParams;
@@ -2424,7 +2433,7 @@ struct ConvertConstructorToDeductionGuideTransform {
   Params.push_back(NewParam);
 }
 
-return buildDeductionGuide(Template->getTemplateParameters(), nullptr,
+return buildDeductionGuide(GetTemplateParameterList(Template), nullptr,
ExplicitSpecifier(), TSI, Loc, Loc, Loc);
   }
 
@@ -5956,12 +5965,7 @@ bool Sema::CheckTemplateArgumentList(
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  // Make sure we get the template parameter list from the most
-  // recent declaration, since that is the only one that is guaranteed to
-  // have all the default template argument information.
-  TemplateParameterList *Params =
-  cast(Template->getMostRecentDecl())
-  ->getTemplateParameters();
+  TemplateParameterList *Params = GetTemplateParameterList(Template);
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();
 
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 4d836839d8c346..388ed7d4cced18 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -44,3 +44,13 @@ namespace Access {
   };
   D z = {Z(), {}};
 }
+
+namespace GH69987 {
+template struct X {};
+template struct X;
+X x;
+
+template struct Y { Y(T); };
+template struct Y ;
+Y y(1);
+};

``




https://github.com/llvm/llvm-project/pull/75569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fix CTAD not respect default template arguments that were added after the definition. (PR #75569)

2023-12-15 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/75569

Fixes https://github.com/llvm/llvm-project/issues/69987

>From 0f49d91b4a22944216cff8654f9c00f892bb02be Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 15 Dec 2023 08:44:57 +0100
Subject: [PATCH] [clang] Fix CTAD not respect default template arguments that
 were added after the definition.

Fixes https://github.com/llvm/llvm-project/issues/69987
---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaTemplate.cpp  | 22 +-
 clang/test/SemaTemplate/ctad.cpp | 10 ++
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5ae6bb8925202..be826e6a44bfc7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -685,6 +685,8 @@ Bug Fixes in This Version
   (`#62157 `_) and
   (`#64885 `_) and
   (`#65568 `_)
+- Fix an issue where clang doesn't respect detault template arguments that
+  are added in a later redeclaration for CTAD. (#69987 
`_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index f10abeaba0d451..450a1a1db0ba86 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1824,6 +1824,15 @@ static void SetNestedNameSpecifier(Sema , TagDecl *T,
 T->setQualifierInfo(SS.getWithLocInContext(S.Context));
 }
 
+// Returns the template parameter list with all default template argument
+// information.
+static TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD) {
+  // Make sure we get the template parameter list from the most
+  // recent declaration, since that is the only one that is guaranteed to
+  // have all the default template argument information.
+  return cast(TD->getMostRecentDecl())->getTemplateParameters();
+}
+
 DeclResult Sema::CheckClassTemplate(
 Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
 CXXScopeSpec , IdentifierInfo *Name, SourceLocation NameLoc,
@@ -2062,7 +2071,7 @@ DeclResult Sema::CheckClassTemplate(
   CheckTemplateParameterList(
   TemplateParams,
   PrevClassTemplate
-  ? PrevClassTemplate->getMostRecentDecl()->getTemplateParameters()
+  ? GetTemplateParameterList(PrevClassTemplate)
   : nullptr,
   (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
SemanticContext->isDependentContext())
@@ -2298,7 +2307,7 @@ struct ConvertConstructorToDeductionGuideTransform {
 //-- The template parameters are the template parameters of the class
 //   template followed by the template parameters (including default
 //   template arguments) of the constructor, if any.
-TemplateParameterList *TemplateParams = Template->getTemplateParameters();
+TemplateParameterList *TemplateParams = GetTemplateParameterList(Template);
 if (FTD) {
   TemplateParameterList *InnerParams = FTD->getTemplateParameters();
   SmallVector AllParams;
@@ -2424,7 +2433,7 @@ struct ConvertConstructorToDeductionGuideTransform {
   Params.push_back(NewParam);
 }
 
-return buildDeductionGuide(Template->getTemplateParameters(), nullptr,
+return buildDeductionGuide(GetTemplateParameterList(Template), nullptr,
ExplicitSpecifier(), TSI, Loc, Loc, Loc);
   }
 
@@ -5956,12 +5965,7 @@ bool Sema::CheckTemplateArgumentList(
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  // Make sure we get the template parameter list from the most
-  // recent declaration, since that is the only one that is guaranteed to
-  // have all the default template argument information.
-  TemplateParameterList *Params =
-  cast(Template->getMostRecentDecl())
-  ->getTemplateParameters();
+  TemplateParameterList *Params = GetTemplateParameterList(Template);
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();
 
diff --git a/clang/test/SemaTemplate/ctad.cpp b/clang/test/SemaTemplate/ctad.cpp
index 4d836839d8c346..388ed7d4cced18 100644
--- a/clang/test/SemaTemplate/ctad.cpp
+++ b/clang/test/SemaTemplate/ctad.cpp
@@ -44,3 +44,13 @@ namespace Access {
   };
   D z = {Z(), {}};
 }
+
+namespace GH69987 {
+template struct X {};
+template struct X;
+X x;
+
+template struct Y { Y(T); };
+template struct Y ;
+Y y(1);
+};

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