[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

You're right, it's visible on the link I posted, the build was already broken! 
Somehow I fat-fingered and didn't hit the first red build but the third one!

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I just double checked, the issue is present on main before this PR was merged, 
it's completely unrelated.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Great, thanks for the quick fix!

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I just pushed a fix.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Yep, I confirm the behavior happens if I add `-triple x86_64-windows-msvc` to 
RUN line.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Weirdly enough the test passes on my machine, latest MacOS.

Maybe the test is not constrained on target, and this is causing differences 
between machines?

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

The quick fix would be to change the expectations of the test, I can do it for 
you.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

So are we reverting here or do you have quick fix available?

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

That test was merged after the last time pre-commit CI was run on this MR.

The change looks like a consequence of my refactoring, we now preserve the type 
sugar from the injected arguments.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Seems like a bot is broken: 
https://lab.llvm.org/buildbot/#/builders/271/builds/7701 ; can you check?

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Richard Smith via cfe-commits

https://github.com/zygoloid commented:

I think we should go ahead with this. The behavior here is subtle but I think 
it does make sense, and we're in the process of proposing this change to WG21.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Erich Keane via cfe-commits

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


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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread via cfe-commits

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

LGTM but gives @zygoloid @erichkeane a few days to review

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-16 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> Despite CWG2398 not being voted in yet, the status in
> 
> https://github.com/llvm/llvm-project/blob/e3f42b02a4129947ca2dd820bfb63ffed83027b7/clang/www/cxx_dr_status.html#L14195-L14200
> 
> should be updated.

The only way to update it is to add a test to `clang/test/CXX/drs`. Me and the 
author had a discussion couple of weeks ago, and the conclusion was that what 
he implements is not (yet) documented in the CWG2398 filing, so we don't have 
anything to write a DR test and claim conformance against. If something has 
changes since then, we should revisit that conclusion.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/90820

>From 39e0af93163068f8de190649eccf91fda84178b6 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

When performing template argument deduction, a template template parameter
containing no packs should be more specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; // #1
template class TT2, class T6> struct A>; // #2

template struct B;
template struct A>;
```

Prior to P0522, candidate #2 would be more specialized.
After P0522, neither is more specialized, so this becomes ambiguous.
With this change, #2 becomes more specialized again,
maintaining compatibility with pre-P0522 implementations.

The problem is that in P0522, candidates are at least as specialized
when matching packs to fixed-size lists both ways, whereas before,
a fixed-size list is more specialized.

This patch keeps the original behavior when checking template arguments
outside deduction, but restores this aspect of pre-P0522 matching
during deduction.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 ++--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++-
 clang/test/SemaTemplate/cwg2398.cpp  | 15 ++
 4 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..7d7eb6c559110 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9133,7 +9133,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9603,7 +9603,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..116d1ac077b29 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8454,8 +8456,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 

[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-15 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/90820

>From c4b72afa655c0e35005dca8aea18e651189f8938 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

When performing template argument deduction, a template template parameter
containing no packs should be more specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; // #1
template class TT2, class T6> struct A>; // #2

template struct B;
template struct A>;
```

Prior to P0522, candidate #2 would be more specialized.
After P0522, neither is more specialized, so this becomes ambiguous.
With this change, #2 becomes more specialized again,
maintaining compatibility with pre-P0522 implementations.

The problem is that in P0522, candidates are at least as specialized
when matching packs to fixed-size lists both ways, whereas before,
a fixed-size list is more specialized.

This patch keeps the original behavior when checking template arguments
outside deduction, but restores this aspect of pre-P0522 matching
during deduction.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 ++--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 67 +++-
 clang/test/SemaTemplate/cwg2398.cpp  | 24 ++---
 4 files changed, 80 insertions(+), 26 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a414aa57f32b..7d7eb6c559110 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9133,7 +9133,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9603,7 +9603,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c7aac068e264b..116d1ac077b29 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6484,7 +6484,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8402,7 +8403,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8454,8 +8456,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 

[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-08 Thread via cfe-commits


@@ -2583,8 +2584,11 @@ DeduceTemplateArguments(Sema , TemplateParameterList 
*TemplateParams,
 return TemplateDeductionResult::MiscellaneousDeductionFailure;
 
   // Perform deduction for this Pi/Ai pair.
-  if (auto Result = DeduceTemplateArguments(S, TemplateParams, P,
-As[ArgIdx], Info, Deduced);
+  TemplateArgument Pi = P, Ai = As[ArgIdx];
+  if (Swapped)
+std::swap(Pi, Ai);

cor3ntin wrote:

We might want a comment here too

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-08 Thread via cfe-commits


@@ -2552,7 +2553,7 @@ DeduceTemplateArguments(Sema , TemplateParameterList 
*TemplateParams,
 ArrayRef As,
 TemplateDeductionInfo ,
 SmallVectorImpl ,
-bool NumberOfArgumentsMustMatch) {
+bool NumberOfArgumentsMustMatch, bool Swapped) {

cor3ntin wrote:

I think this needs a comment.
`Swapped` should be defaulted and have a better name.
Maybe `ForPartialOrderingOfDeducedTemplateTemplateArgument`

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-03 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Vlad Serebrennikov via cfe-commits




Endilll wrote:

> Sounds like should perhaps note that we are implementing our own resolution, 
> until there's an update to the cwg issue that can be referred to?

Our tooling is not ready for describing own own resolutions, unfortunately. 
Ideally if we have a resolution, it should be submitted to CWG and documented 
in the issue, making it easy to reference.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

> Sounds like should perhaps note that we are implementing our own resolution, 
> until there's an update to the cwg issue that can be referred to?

That could be. Is there another similar issue we could use as a reference on 
the format for this?

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

It would not be splitting though, it would be wholesale duplication in that 
case.
This file is the only part of the suite still testing the old non-conformant 
mode, and I fail to see a test case we wouldn't be wanting to test on both.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread via cfe-commits




h-vetinari wrote:

> Note we are not implementing the solution Jason posted on the core mailing 
> list, neither on the previous patch, as we have a better solution than 
> current GCC on this, nor on this MR, as GCC implements no such workaround and 
> still fails this test.

Sounds like should perhaps note that we are implementing our own resolution, 
until there's an update to the cwg issue that can be referred to?

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Vlad Serebrennikov via cfe-commits




Endilll wrote:

> Also, this needs to test a non-conforming mode until we finally remove the 
> corresponding flag, and that is against the rules for the DR suite.

You should be able to split conforming part of the test into DR test, though.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

Note we are not implementing the solution Jason posted on the core mailing 
list, neither on the previous patch, as we have a better solution than current 
GCC on this, nor on this MR, as GCC implements no such workaround and still 
fails this test.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Vlad Serebrennikov via cfe-commits




Endilll wrote:

This file is not going to be picked up by the `make_cxx_dr_status`, because 
it's not in `clang/test/CXX/drs`. If we're implementing what Jason Merill 
speaks of (_In deduction we can determine that P is more specialized than B, 
then substitute B into P, and then compare B to B_), then I 
agree with `// cwg2398: 19 drafting 2016-12-03` marking.

In the previous PR on this topic I asked for this test to be moved out of DR 
test suite, because it was testing with `-fno-relaxed-template-template-args`, 
which is not a conformance mode. This still holds, so this file can't be simply 
moved to DR test suite as is.

I also don't see why CWG2398 test can't be placed in `dr23xx.cpp`. We place DR 
tests in separate files only if they require special handling. Typical case is 
codegen tests. Note that special handling doesn't mean testing non-conformance 
modes, or reduced number of conformance modes.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Matheus Izvekov via cfe-commits




mizvekov wrote:

I had some discussion about that with @Endilll on the previous MR regarding 
this core issue: https://github.com/llvm/llvm-project/pull/89807

Since there is no posting at all in core about any possible solutions, I wanted 
to get feedback from them before claiming to be implementing a solution in the 
public documentation.

Also, this needs to test a non-confirming mode until we finally remove the 
corresponding flag, and that is against the rules for the DR suite.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread via cfe-commits




h-vetinari wrote:

AFAIU, for this to be picked up by 
[make_cxx_dr_status](https://github.com/llvm/llvm-project/blob/main/clang/www/make_cxx_dr_status)
 correctly, this file should have a comment near the top like:
```
// cwg2398: 19 drafting 2016-12-03
```
and for consistency should be mentioned in `dr23xx.cpp` like so:
https://github.com/llvm/llvm-project/blob/b86e0992bfa6c58be077d82d824016f590ac5d90/clang/test/CXX/drs/dr23xx.cpp#L276

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread via cfe-commits

https://github.com/h-vetinari commented:

Despite CWG2398 not being voted in yet, the status in
https://github.com/llvm/llvm-project/blob/e3f42b02a4129947ca2dd820bfb63ffed83027b7/clang/www/cxx_dr_status.html#L14195-L14200

should be updated. 

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread via cfe-commits

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-02 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes look good to me.

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


[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This solves some ambuguity introduced in P0522 regarding how template template 
parameters are partially ordered, and should reduce the negative impact of 
enabling `-frelaxed-template-template-args` by default.

A template template parameter containing no packs should be more specialized 
than one that does.

Given the following example:
```C++
templateclass T2 struct A;
templatetemplateclass ...T3s class TT1, class T4 struct 
ATT1T4; #1
templatetemplateclassT5  class TT2, class T6 struct 
ATT2T6; #2

templateclass T1 struct B;
template struct ABchar;
```

Prior to P0522, #2 would be the only viable candidate. After P0522, 
#1 is also viable, and neither is considered more specialized, so this 
becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is 
picked and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in 
`[temp.arg.template]/4` are defined in terms of a rewrite to function 
templates, but in the case of partial ordering, the rules on how P and A lists 
are matched to each other is swapped regarding how specialization makes sense 
conceptually.

---

Since this changes provisional implementation of CWG2398 which has not been 
released yet, and already contains a changelog entry, we don't provide a 
changelog entry here.

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


4 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+3-2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+6-4) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+59-20) 
- (modified) clang/test/SemaTemplate/cwg2398.cpp (-6) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a80ac6dbc76137..2bea8732f61fcd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9238,7 +9238,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9708,7 +9708,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 989f3995ca5991..2c921d4365db0a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6384,7 +6384,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8296,7 +8297,8 @@ static void DiagnoseTemplateParameterListArityMismatch(
 /// It returns true if an error occurred, and false otherwise.
 bool Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc ) {
+ TemplateArgumentLoc ,
+ bool IsDeduced) {
   TemplateName Name = Arg.getArgument().getAsTemplateOrTemplatePattern();
   TemplateDecl *Template = Name.getAsTemplateDecl();
   if (!Template) {
@@ -8348,8 +8350,8 @@ bool 
Sema::CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
 !Template->hasAssociatedConstraints())
   return false;
 
-if (isTemplateTemplateParameterAtLeastAsSpecializedAs(Params, Template,
-  Arg.getLocation())) {
+if (isTemplateTemplateParameterAtLeastAsSpecializedAs(
+Params, Template, Arg.getLocation(), IsDeduced)) {
   // P2113
   // C++20[temp.func.order]p2
   //   [...] If both deductions succeed, the partial ordering selects the
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e4422827173..4fbaecd7dba960 100644
--- 

[clang] [clang] Implement provisional wording for CWG2398 regarding packs (PR #90820)

2024-05-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/90820

This solves some ambuguity introduced in P0522 regarding how template template 
parameters are partially ordered, and should reduce the negative impact of 
enabling `-frelaxed-template-template-args` by default.

A template template parameter containing no packs should be more specialized 
than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; #1
template class TT2, class T6> struct A>; #2

template struct B;
template struct A>;
```

Prior to P0522, #2 would be the only viable candidate. After P0522, #1 is also 
viable, and neither is considered more specialized, so this becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is picked 
and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in 
`[temp.arg.template]/4` are defined in terms of a rewrite to function 
templates, but in the case of partial ordering, the rules on how P and A lists 
are matched to each other is swapped regarding how specialization makes sense 
conceptually.

---

Since this changes provisional implementation of CWG2398 which has not been 
released yet, and already contains a changelog entry, we don't provide a 
changelog entry here.

>From b7df9a342724479e129af252f2ff37229f30d41b Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 1 May 2024 22:29:45 -0300
Subject: [PATCH] [clang] Implement provisional wording for CWG2398 regarding
 packs

This solves some ambuguity introduced in P0522 regarding how
template template parameters are partially ordered, and should reduce
the negative impact of enabling `-frelaxed-template-template-args`
by default.

A template template parameter containing no packs should be more
specialized than one that does.

Given the following example:
```C++
template struct A;
template class TT1, class T4> struct A>; #1
template class TT2, class T6> struct A>; #2

template struct B;
template struct A>;
```

Prior to P0522, #2 would be the only viable candidate.
After P0522, #1 is also viable, and neither is considered more specialized,
so this becomes ambiguous.
With this change, #2 is considered more specialized, so that is what is picked
and we remain compatible with pre-P0522 implementations.

The problem we solve here is that the specialization rules in
`[temp.arg.template]/4` are defined in terms of a rewrite to
function templates, but in the case of partial ordering, the
rules on how P and A lists are matched to each other
is swapped regarding how specialization makes sense conceptually.

---

Since this changes provisional implementation of CWG2398 which has
not been released yet, and already contains a changelog entry,
we don't provide a changelog entry here.
---
 clang/include/clang/Sema/Sema.h  |  5 +-
 clang/lib/Sema/SemaTemplate.cpp  | 10 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp | 79 ++--
 clang/test/SemaTemplate/cwg2398.cpp  |  6 --
 4 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a80ac6dbc76137..2bea8732f61fcd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9238,7 +9238,7 @@ class Sema final : public SemaBase {
CheckTemplateArgumentKind CTAK);
   bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
  TemplateParameterList *Params,
- TemplateArgumentLoc );
+ TemplateArgumentLoc , bool IsDeduced);
 
   void NoteTemplateLocation(const NamedDecl ,
 std::optional ParamRange = {});
@@ -9708,7 +9708,8 @@ class Sema final : public SemaBase {
 sema::TemplateDeductionInfo );
 
   bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
-  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc);
+  TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc,
+  bool IsDeduced);
 
   void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced,
   unsigned Depth, llvm::SmallBitVector );
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 989f3995ca5991..2c921d4365db0a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6384,7 +6384,8 @@ bool Sema::CheckTemplateArgument(
 
   case TemplateArgument::Template:
   case TemplateArgument::TemplateExpansion:
-if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
+if (CheckTemplateTemplateArgument(TempParm, Params, Arg,
+  /*IsDeduced=*/CTAK != CTAK_Specified))
   return true;
 
 SugaredConverted.push_back(Arg.getArgument());
@@ -8296,7