[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-12-01 Thread via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

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

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

LGTM

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-30 Thread via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-30 Thread via cfe-commits


@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;

cor3ntin wrote:

After offline, i changed it. Let me know if that makes you happier.

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/73103

>From 074d18d3805b067a5442bea94816d01319a29083 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 22 Nov 2023 11:43:07 +0100
Subject: [PATCH 1/5] [Clang] Implement P2308R1 - Template Parameter
 Initialization.

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450
and CWG2049.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  4 +
 clang/lib/Parse/ParseTemplate.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++
 clang/lib/Sema/SemaTemplate.cpp   | 96 ---
 clang/test/CXX/drs/dr20xx.cpp |  8 ++
 clang/test/CXX/drs/dr24xx.cpp | 32 +++
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  6 +-
 .../SemaTemplate/temp_arg_nontype_cxx2c.cpp   | 74 ++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 11 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr24xx.cpp
 create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2ee946af32bf197..dfeaae404ce63d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,9 @@ C++2c Feature Support
 
 - Implemented `P2864R2 Remove Deprecated Arithmetic Conversion on Enumerations 
From C++26 `_.
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e75a8bdb1fc72ff..937fcb3ce6079d7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3932,6 +3932,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3a3e9234469d393..e2ca2a0cfb89433 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;
+  return ::EvaluateConvertedConstantExpression(*this, E, T, Value, CCE,
+  

[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits


@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;

cor3ntin wrote:

That's because I wanted to use the same pattern as 
CheckConvertedConstantExpression/BuildConvertedConstantExpression which both 
defer to a static function.
They probably could all be changed to be members of Sema if we wanted to.
I'd rather not do that in this patch though

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/73103

>From 4709819fb2e7f45f9429f1a7fc79923abf0f9691 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 22 Nov 2023 11:43:07 +0100
Subject: [PATCH 1/4] [Clang] Implement P2308R1 - Template Parameter
 Initialization.

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450
and CWG2049.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  4 +
 clang/lib/Parse/ParseTemplate.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++
 clang/lib/Sema/SemaTemplate.cpp   | 96 ---
 clang/test/CXX/drs/dr20xx.cpp |  8 ++
 clang/test/CXX/drs/dr24xx.cpp | 32 +++
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  6 +-
 .../SemaTemplate/temp_arg_nontype_cxx2c.cpp   | 74 ++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 11 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr24xx.cpp
 create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4b0a2cb5e0..70b6a24e6054814 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,9 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e75a8bdb1fc72ff..937fcb3ce6079d7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3932,6 +3932,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3a3e9234469d393..e2ca2a0cfb89433 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;
+  

[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Tom Honermann via cfe-commits


@@ -61,6 +61,14 @@ namespace dr2026 { // dr2026: 11
   }
 }
 
+namespace dr2049 { // dr2049: 18 drafting
+#if __cplusplus > 202002L
+template  struct X {};
+X<> a;
+X b;

tahonermann wrote:

Perhaps add a same-type static assertion for `a` and `b` to ensure a consistent 
specialization is selected?

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann commented:

Looks like good work to me!

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Tom Honermann via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/73103

>From 4709819fb2e7f45f9429f1a7fc79923abf0f9691 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 22 Nov 2023 11:43:07 +0100
Subject: [PATCH 1/3] [Clang] Implement P2308R1 - Template Parameter
 Initialization.

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450
and CWG2049.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  4 +
 clang/lib/Parse/ParseTemplate.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++
 clang/lib/Sema/SemaTemplate.cpp   | 96 ---
 clang/test/CXX/drs/dr20xx.cpp |  8 ++
 clang/test/CXX/drs/dr24xx.cpp | 32 +++
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  6 +-
 .../SemaTemplate/temp_arg_nontype_cxx2c.cpp   | 74 ++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 11 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr24xx.cpp
 create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4b0a2cb5e0..70b6a24e6054814 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,9 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e75a8bdb1fc72ff..937fcb3ce6079d7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3932,6 +3932,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3a3e9234469d393..e2ca2a0cfb89433 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;
+  

[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/73103

>From 4709819fb2e7f45f9429f1a7fc79923abf0f9691 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 22 Nov 2023 11:43:07 +0100
Subject: [PATCH 1/2] [Clang] Implement P2308R1 - Template Parameter
 Initialization.

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450
and CWG2049.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  4 +
 clang/lib/Parse/ParseTemplate.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++
 clang/lib/Sema/SemaTemplate.cpp   | 96 ---
 clang/test/CXX/drs/dr20xx.cpp |  8 ++
 clang/test/CXX/drs/dr24xx.cpp | 32 +++
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  6 +-
 .../SemaTemplate/temp_arg_nontype_cxx2c.cpp   | 74 ++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 11 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr24xx.cpp
 create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4b0a2cb5e0..70b6a24e6054814 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,9 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e75a8bdb1fc72ff..937fcb3ce6079d7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3932,6 +3932,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3a3e9234469d393..e2ca2a0cfb89433 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6226,6 +6226,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;
+  

[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Aaron Ballman via cfe-commits


@@ -62,7 +62,7 @@ namespace ClassNTTP {
   template constexpr int f() { return a.y; }
   static_assert(f() == 2);
 
-  template int id;
+  template int id; // expected-note {{passing argument to parameter 'a' 
here}}

AaronBallman wrote:

Ahhh, it was just out of sight. Yeah might as well switch to a bookmark 
instead. I don't feel that strongly though.

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread via cfe-commits


@@ -62,7 +62,7 @@ namespace ClassNTTP {
   template constexpr int f() { return a.y; }
   static_assert(f() == 2);
 
-  template int id;
+  template int id; // expected-note {{passing argument to parameter 'a' 
here}}

cor3ntin wrote:

L70. you want me to use a label i guess?

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -fcxx-exceptions -pedantic-errors \

AaronBallman wrote:

I don't think we need `-fexceptions -fcxx-exceptions -Wno-variadic-macros 
-Wno-c11-extensions` either.

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Aaron Ballman via cfe-commits


@@ -62,7 +62,7 @@ namespace ClassNTTP {
   template constexpr int f() { return a.y; }
   static_assert(f() == 2);
 
-  template int id;
+  template int id; // expected-note {{passing argument to parameter 'a' 
here}}

AaronBallman wrote:

What diagnostic is this note associated with?

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-29 Thread Erich Keane via cfe-commits

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

I dont think the triple is necessary for the test, otherwise this LGTM!

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-22 Thread Vlad Serebrennikov via cfe-commits

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

DR test side looks good, except for a small nit.

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-22 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-22 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -fcxx-exceptions -pedantic-errors \

Endilll wrote:

Is triple necessary for the test?

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


[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450 and CWG2049.

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


11 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Sema/Sema.h (+4) 
- (modified) clang/lib/Parse/ParseTemplate.cpp (+8-3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+9) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+63-33) 
- (modified) clang/test/CXX/drs/dr20xx.cpp (+8) 
- (added) clang/test/CXX/drs/dr24xx.cpp (+32) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+3-3) 
- (added) clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp (+74) 
- (modified) clang/www/cxx_dr_status.html (+3-3) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 157afd9e8629152..b3079229c959789 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,9 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 59806bcbcbb2dbc..f1b60716a2ee945 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3923,6 +3923,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 64607e28b8b35e6..b4a324b9863fa18 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6206,6 +6206,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+ Sema::CCEKind CCE,
+ bool RequireInt) {
+
+  APValue PreNarrowingValue;
+  return ::EvaluateConvertedConstantExpression(*this, E, T, Value, CCE,
+   RequireInt, PreNarrowingValue);
+}
 
 /// dropPointerConversions - If the given standard conversion sequence
 /// involves any pointer conversions, remove them.  This may change
diff --git 

[clang] [Clang] Implement P2308R1 - Template Parameter Initialization. (PR #73103)

2023-11-22 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/73103

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450 and CWG2049.

>From 90a9c92ce532af7c6346a381499780f158cd26ca Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 22 Nov 2023 11:43:07 +0100
Subject: [PATCH] [Clang] Implement P2308R1 - Template Parameter
 Initialization.

https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html

This implements P2308R1 as a DR and resolves CWG2459, CWG2450
and CWG2049.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Sema/Sema.h   |  4 +
 clang/lib/Parse/ParseTemplate.cpp | 11 ++-
 clang/lib/Sema/SemaOverload.cpp   |  9 ++
 clang/lib/Sema/SemaTemplate.cpp   | 96 ---
 clang/test/CXX/drs/dr20xx.cpp |  8 ++
 clang/test/CXX/drs/dr24xx.cpp | 32 +++
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  6 +-
 .../SemaTemplate/temp_arg_nontype_cxx2c.cpp   | 74 ++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 11 files changed, 208 insertions(+), 43 deletions(-)
 create mode 100644 clang/test/CXX/drs/dr24xx.cpp
 create mode 100644 clang/test/SemaTemplate/temp_arg_nontype_cxx2c.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 157afd9e8629152..b3079229c959789 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,9 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2361R6 Template parameter initialization 
`_.
+  This change is applied as a DR in all language modes.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 59806bcbcbb2dbc..f1b60716a2ee945 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3923,6 +3923,10 @@ class Sema final {
   APValue , CCEKind CCE,
   NamedDecl *Dest = nullptr);
 
+  ExprResult EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue , CCEKind CCE,
+ bool RequireInt);
+
   /// Abstract base class used to perform a contextual implicit
   /// conversion from an expression to any type passing a filter.
   class ContextualImplicitConverter {
diff --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index f556d0e6d4f8b6e..64fe4d50bba27bf 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1062,8 +1062,7 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, 
unsigned Position) {
   ++CurTemplateDepthTracker;
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-  DefaultArg =
-  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseInitializer());
   if (DefaultArg.isInvalid())
 SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
 }
@@ -1582,6 +1581,8 @@ ParsedTemplateArgument 
Parser::ParseTemplateTemplateArgument() {
 /// constant-expression
 /// type-id
 /// id-expression
+/// braced-init-list  [C++26, DR]
+///
 ParsedTemplateArgument Parser::ParseTemplateArgument() {
   // C++ [temp.arg]p2:
   //   In a template-argument, an ambiguity between a type-id and an
@@ -1619,8 +1620,12 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
   }
 
   // Parse a non-type template argument.
+  ExprResult ExprArg;
   SourceLocation Loc = Tok.getLocation();
-  ExprResult ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))
+ExprArg = ParseBraceInitializer();
+  else
+ExprArg = ParseConstantExpressionInExprEvalContext(MaybeTypeCast);
   if (ExprArg.isInvalid() || !ExprArg.get()) {
 return ParsedTemplateArgument();
   }
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 64607e28b8b35e6..b4a324b9863fa18 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6206,6 +6206,15 @@ ExprResult Sema::CheckConvertedConstantExpression(Expr 
*From, QualType T,
   return R;
 }
 
+ExprResult Sema::EvaluateConvertedConstantExpression(Expr *E, QualType T,
+ APValue ,
+