[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

AidanGoldfarb wrote:

ping @pinskia @AaronBallman 

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-25 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/6] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/6] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/6] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/6] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/6] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/3] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/3] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/3] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/4] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/4] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/4] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/4] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

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


[clang] [clang][sema] (PR #117507)

2024-11-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb created 
https://github.com/llvm/llvm-project/pull/117507

This PR addresses #116880 

Updated 
[LanguageExtensions.rst](https://github.com/llvm/llvm-project/blob/main/clang/docs/LanguageExtensions.rst)
 to include support for C++11 enumerations with a fixed underlying type in C. 
Included a note that this is only a language extension in https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Features.def)
 to support for `__has_extension(c_fixed_enum)`.

Updated 
[enum.c](https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/enum.c) 
to ensure support of C++11 enumerations with a fixed underlying type in both 
From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/2] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/2] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/8] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/8] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/8] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/8] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/8] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits


@@ -121,6 +121,14 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
+// Enumerations with a fixed underlying type. 
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L && !__has_extension(c_fixed_enum)

AidanGoldfarb wrote:

Updated this, my thought process was to check for `__has_extension()` when 
=C23. 
Previously I had only checked for `__has_extension()` when >=C23, which in my 
mind was both incomplete (`__has_feature()` missing) and incorrect 
(`__has_extension()` should be associated with >C23 not >=C23).

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-27 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-28 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/9] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/9] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/9] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/9] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/9] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-28 Thread Aidan Goldfarb via cfe-commits


@@ -121,6 +121,16 @@ int NegativeShortTest[NegativeShort == -1 ? 1 : -1];
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
 
+// Enumerations with a fixed underlying type. 
+// https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L && !__has_feature(c_fixed_enum)
+#error c_fixed_enum should be set a feature in C23 mode
+#elif __STDC_VERSION__ < 202311L && !__has_extension(c_fixed_enum)
+#error c_fixed_enum should be a language extension in https://github.com/llvm/llvm-project/pull/117507
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-26 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/7] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/7] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/7] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/7] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/7] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-25 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/5] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/5] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/5] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/5] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 572f9dbceee08d67271710695aa5c96e22fb92e0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Mon, 25 Nov 2024 10:19:11 -0500
Subject: [PATCH 5/5] Update clang/tes

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-25 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/5] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/5] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/5] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/5] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/5] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

[clang] [llvm] Port `LowerINT_TO_FP()` and `LowerFP_TO_INT` to `TargetLowering.cpp` (PR #118830)

2024-12-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [llvm] Port `LowerINT_TO_FP()` and `LowerFP_TO_INT` to `TargetLowering.cpp` (PR #118830)

2024-12-05 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb created 
https://github.com/llvm/llvm-project/pull/118830

Addresses #116695, specifically [int -> fp / fp -> 
int](https://github.com/llvm/llvm-project/blob/f8d1905a24c16bf6db42d428672401156ef6a473/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L2777-L2806).



>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 01/10] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 02/10] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 03/10] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 04/10] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 872

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-12-03 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 01/10] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 02/10] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 03/10] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 04/10] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 05/10] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 +

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-30 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"
+"|: could not convert '%1' from %2 to %3}0">;

AidanGoldfarb wrote:

I'll try that. This commit introduced some unexpected test failures, I believe 
because of this change. I will revisit soon, as well as your proposed lambda 
refactor. Thank you!

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-04 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-31 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"
+"|: could not convert '%1' from %2 to %3}0">;

AidanGoldfarb wrote:

Implemented. I put the `NoteTemplateParameterLocation` call after the diag, so 
it appears as:
```
source.cpp:80:5: error: no matching function for call to 'foo'
   80 | foo();
  | ^~
3
source.cpp:77:13: note: candidate template ignored: invalid 
explicitly-specified argument: could not convert 'false' from 'bool' to 
'endianness'
   77 | inline void foo() {}
  | ^
source.cpp:76:22: note: template parameter is declared here
   76 | template 
  |  ^
```
Let me know if that looks good. 

Separately, I found an interesting case that I had not caught before due to the 
more generic `//expected-note {{invalid explicitly-specified argument}}` 
allowing the confusing error message seen below. The case from 
`clang/test/CXX/temp/temp.param/p8-cxx20.cpp`

```
namespace ConstDestruction {
  struct D {
int n;
bool can_destroy;

constexpr ~D() {
  if (!can_destroy)
throw "oh no"; // expected-note {{subexpression not valid}}
}
  };

  template 
  void f() {} // expected-note 2{{invalid explicitly-specified argument}}

  void g() {
f();
f(); // expected-error {{no matching function}}
  }
}
```  
The root cause being an ill-formed constexpr. In this case, the diag message 
`candidate template ignored: invalid explicitly-specified argument: could not 
convert 'D{0, false}' from 'D' to 'D'` cannot be what we want. Although it is 
an invalid explicitly specified argument, it seems to be to be in a separate 
category from other tests. Should I look into emitting a unique error message 
along the lines of `template argument ‘D{0, false}’ is not a valid constant 
expression`?

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-31 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"

AidanGoldfarb wrote:

Ok, I now see well what you mean. I will clean up the messages and attempt to 
add the previously mentioned `constexpr` case 

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-31 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-31 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"
+"|: could not convert '%1' from %2 to %3}0">;

AidanGoldfarb wrote:

[GCC](https://godbolt.org/z/7ax4n77dv) provides some nice information IMO. I 
will try to make the output more imformative.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-04 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"

AidanGoldfarb wrote:

FYI: I plan to resolve this after the ill formed const expression business. The 
most recent push still contains tests which expect awkward error messages.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-04 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"
+"|: could not convert '%1' from %2 to %3}0">;

AidanGoldfarb wrote:

Noted, thank you. I definitely want to dig into the issue, but I am happy to 
divert it to another PR per your advice. 

I will revert the relevant cases to their original messages (or whatever we 
determine the new default to be). For the test in `cwg3xx.cpp` that would be 
`candidate template ignored: invalid explicitly-specified argument for 1st 
template parameter` (the original unnamed case).

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"

AidanGoldfarb wrote:

Updated the diags. I am not thrilled about 
```
// FIXME: This is a hack. We should emit a better message 
// for ill-formed const exprs in >=C++20.
if (qt.getCanonicalType() ==
  SecondArg.getAsType().getCanonicalType() &&
  __cplusplus <= 201703)
```
but I couldn't find another way to avoid the case. Would be resolved in a 
future PR, along with better messages for `TemplateTemplateParmDecl` cases. 

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-02-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/22] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits


@@ -4870,9 +4870,21 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch_named_temptemppd : Note<
 "candidate template ignored: invalid explicitly-specified argument "
 "for template parameter %0">;
+def note_ovl_candidate_explicit_arg_mismatch_named_ttpd : Note<
+"candidate template ignored: invalid explicitly-specified argument "
+"for template parameter %0: "
+"expected a type, but got value '%1' (of type %2)">;
+def note_ovl_candidate_explicit_arg_mismatch_named_nttpd_b : Note<
+"candidate template ignored: invalid explicitly-specified argument "
+"for template parameter %0: "
+"could not convert '%1' from %2 to %3">;
+def note_ovl_candidate_explicit_arg_mismatch_named_nttpd_a : Note<
+"candidate template ignored: invalid explicitly-specified argument "
+"for template parameter %0: "
+"expected constant of type %1 got type %2">;

AidanGoldfarb wrote:

I believe I resolved this with the merging of diag messages, but I am not 
exactly sure what you mean. Please let me know if I misunderstood.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,37 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {

AidanGoldfarb wrote:

My recent change improved the caret imo. I used `getEndLoc()`, I wasn't sure if 
there was a better way to capture `SourceRange` into a `SourceLocation` that 
Diag requires

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/23] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-30 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/24] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-30 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,37 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {

AidanGoldfarb wrote:

My most recent change split up the information into two diags, much like GCC 
and what I think you were suggesting. Please let me know if this was what you 
had in mind

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-30 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,38 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {
+  TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+  TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+  if (auto *TTPD = dyn_cast(ParamD)) {
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named)
+<< 1 << ParamD->getDeclName() << FirstArg << SecondArg
+<< TTPD->getSourceRange();
+
+  } else if (auto *NTTPD = dyn_cast(ParamD)) {
+if (SecondArg.isNull()) {
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named)
+  << 3 << ParamD->getDeclName() << NTTPD->getType() << FirstArg
+  << NTTPD->getSourceRange();
+} else {
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named)
+  << 2 << ParamD->getDeclName() << FirstArg << SecondArg
+  << NTTPD->getType() << NTTPD->getSourceRange();
+}
+  } else if (auto *TTempPD = dyn_cast(ParamD)) {
+// FIXME: Emit a better message here
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named)
+<< 4 << ParamD->getDeclName() << TTempPD->getSourceRange();
+  } else
+llvm_unreachable("unexpected param decl kind");
+} else {
   int index = 0;

AidanGoldfarb wrote:

With the last refactor I think the code is better, but its possible I 
blissfully ignored some coding practices...

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/6] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/6] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/6] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From cfda1e8d3bf61a84fdebd4a0b61ca114811e2af0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/6] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index befa411e882b4c..5561e15e852448 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Added support for the ``__nullptr`` keyword. 
 
 C2y Feature Support
 ^^^

>From 611c7022d6be9794e8242484b011fdf3be328353 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/6] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct S *);
-void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
 _Static_assert(__nullptr == 0); // Test tha

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/14] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-22 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/15] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-22 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11715,52 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {
+  TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+  std::string ParamName = ParamD->getNameAsString();
+  TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+  if (auto *TTPD = dyn_cast(ParamD)) {
+if (TTPD->wasDeclaredWithTypename())
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+  << ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+  << "type";
+else {
+  // TODO write tests for type constrained classes
+  if (auto *constraint = TTPD->getTypeConstraint())

AidanGoldfarb wrote:

I am still not sure how I want to handle concepts, as [some 
information](https://en.cppreference.com/w/cpp/concepts) leads me to believe 
there should be no diagnostic at all (ill formed). I will make sure there is no 
unused variable when I ready the PR for review.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-22 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11715,52 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {
+  TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+  std::string ParamName = ParamD->getNameAsString();
+  TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+  if (auto *TTPD = dyn_cast(ParamD)) {
+if (TTPD->wasDeclaredWithTypename())
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+  << ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+  << "type";
+else {
+  // TODO write tests for type constrained classes
+  if (auto *constraint = TTPD->getTypeConstraint())
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+<< ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+<< "valid type-constrained class";
+  else
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+<< ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+<< "class";
+}
+  } else if (auto *NTTPD = dyn_cast(ParamD)) {
+if (SecondArg.isNull()) {
+  // Expected constant of type 'int', got type 'int'
+  S.Diag(Templated->getLocation(),
+ 
diag::note_ovl_candidate_explicit_arg_mismatch_named_nttpd_nsp)
+  << ParamD->getDeclName() << FirstArg << NTTPD->getType();
+} else {
+  // Could not convert A from B to C
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_nttpd_sp)
+  << ParamD->getDeclName() << FirstArg << SecondArg
+  << NTTPD->getType();
+}
+  } else if (auto *TTempPD = dyn_cast(ParamD)) {

AidanGoldfarb wrote:

Thank you for the suggestion. However, I am planning to at least attempt to 
make a better error message in this situation, so I would need this cast. 

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-22 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/16] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-21 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/17] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits


@@ -4872,7 +4872,19 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for template parameter %0: ">;

AidanGoldfarb wrote:

resolved in last commit

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/8] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/8] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/8] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From cfda1e8d3bf61a84fdebd4a0b61ca114811e2af0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/8] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index befa411e882b4c..5561e15e852448 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Added support for the ``__nullptr`` keyword. 
 
 C2y Feature Support
 ^^^

>From 611c7022d6be9794e8242484b011fdf3be328353 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/8] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct S *);
-void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
 _Static_assert(__nullptr == 0); // Test tha

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/7] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/7] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/7] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From cfda1e8d3bf61a84fdebd4a0b61ca114811e2af0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/7] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index befa411e882b4c..5561e15e852448 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Added support for the ``__nullptr`` keyword. 
 
 C2y Feature Support
 ^^^

>From 611c7022d6be9794e8242484b011fdf3be328353 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/7] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct S *);
-void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
 _Static_assert(__nullptr == 0); // Test tha

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,49 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {
+  TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+  std::string ParamName = ParamD->getNameAsString();
+  TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+
+  if (auto *TTPD = dyn_cast(ParamD)) {
+if (TTPD->wasDeclaredWithTypename())
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+  << ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+  << "type";
+else {
+  if (TTPD->getTypeConstraint())
+llvm_unreachable("ill-formed program");
+  else
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named_ttpd)
+<< ParamD->getDeclName() << FirstArg << SecondArg << ParamName
+<< "class";
+}
+  } else if (auto *NTTPD = dyn_cast(ParamD)) {
+if (SecondArg.isNull()) {
+  // Expected constant of type 'int', got type 'int'
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_nttpd_a)
+  << ParamD->getDeclName() << FirstArg << NTTPD->getType();
+} else {
+  // Could not convert A from B to C
+  S.Diag(Templated->getLocation(),
+ diag::note_ovl_candidate_explicit_arg_mismatch_named_nttpd_b)
+  << ParamD->getDeclName() << FirstArg << SecondArg
+  << NTTPD->getType();
+}
+  } else if (auto *TTempPD = dyn_cast(ParamD)) {
+TTempPD->dump();
+S.Diag(Templated->getLocation(),
+   diag::note_ovl_candidate_explicit_arg_mismatch_named)
+<< ParamD->getDeclName();

AidanGoldfarb wrote:

My initial thought was no, as we are casting a `NamedDecl` not a 
`TemplateParameter`. If the latter was case, one of the three casts would be 
guaranteed to succeed, but I am not sure if that is still the case with the 
former. 

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-24 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-18 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/4] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/4] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/4] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From cfda1e8d3bf61a84fdebd4a0b61ca114811e2af0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/4] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index befa411e882b4c..5561e15e852448 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Added support for the ``__nullptr`` keyword. 
 
 C2y Feature Support
 ^^^

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-18 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/3] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/3] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/3] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-18 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From 51372333df218cfb4fa8dcc0cebee03c0e3ebc5f Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/5] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From bd9fe6016717b805c37e7fce5ee70dddc6c42eb7 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/5] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From 7ec48387c8a3e9b831fd3c5b1400ad5e5ee32e21 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/5] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From cfda1e8d3bf61a84fdebd4a0b61ca114811e2af0 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/5] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index befa411e882b4c..5561e15e852448 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -325,6 +325,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Added support for the ``__nullptr`` keyword. 
 
 C2y Feature Support
 ^^^

>From 611c7022d6be9794e8242484b011fdf3be328353 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/5] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct S *);
-void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
 _Static_assert(__nullptr == 0); // Test tha

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/4] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/5] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/6] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/9] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/7] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/11] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/10] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 1/8] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondArg

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/12] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-20 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/13] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-25 Thread Aidan Goldfarb via cfe-commits

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 01/11] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 02/11] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 03/11] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 04/11] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 05/11] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void 

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 01/12] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 02/12] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 03/12] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 04/12] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 05/12] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void 

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

AidanGoldfarb wrote:

Updating LanguageExtensions.rst before merge (and final reviews). 

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


[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/8] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/8] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/8] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/8] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/8] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 01/13] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 02/13] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 03/13] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 04/13] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 05/13] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void 

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 1/9] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 2/9] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 3/9] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 4/9] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 5/9] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void foo(struct

[clang] [clang] Add __nullptr as a keyword to C (PR #123119)

2025-01-27 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/123119

>From bc5d1419d94ac492c0fcf62a74844eb43ce17f1a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Wed, 15 Jan 2025 15:24:12 -0500
Subject: [PATCH 01/10] __nullptr -> KEYALL, added relevant test

---
 clang/include/clang/Basic/TokenKinds.def | 2 +-
 clang/test/Sema/nullptr.c| 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 2c692c999bdff5..8902a20b07ffa8 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -707,7 +707,7 @@ ALIAS("__decltype"   , decltype , KEYCXX)
 ALIAS("__imag__" , __imag   , KEYALL)
 ALIAS("__inline" , inline   , KEYALL)
 ALIAS("__inline__"   , inline   , KEYALL)
-ALIAS("__nullptr", nullptr  , KEYCXX)
+ALIAS("__nullptr", nullptr  , KEYALL)
 ALIAS("__real__" , __real   , KEYALL)
 ALIAS("__restrict"   , restrict , KEYALL)
 ALIAS("__restrict__" , restrict , KEYALL)
diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index d11765a9c881a1..64095fc00691cd 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -108,3 +108,6 @@ void test_f1() {
   int ir = (f1)(nullptr);
 }
 
+// __nullptr keyword in C
+void foo(void *);
+void bar() { foo(__nullptr); }
\ No newline at end of file

>From 7230332a3e9c95f547ffb9eaf76add48666e1e67 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 17 Jan 2025 12:00:04 -0500
Subject: [PATCH 02/10] Added additional tests

static_assert(nullptr == __nullptr) and 
static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false))
---
 clang/test/Sema/nullptr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index 64095fc00691cd..ca2a8aa064caf3 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -110,4 +110,6 @@ void test_f1() {
 
 // __nullptr keyword in C
 void foo(void *);
-void bar() { foo(__nullptr); }
\ No newline at end of file
+void bar() { foo(__nullptr); }
+static_assert(nullptr == __nullptr);
+static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));

>From ff8bf0dace7912ecb64d8a2114a1b465071908ad Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 11:56:02 -0500
Subject: [PATCH 03/10] Update nullptr.c

---
 clang/test/Sema/nullptr.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index ca2a8aa064caf3..bbe3d4c2ece7ff 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,3 +113,8 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
+
+void foo(struct S *);
+void bar() { foo(__nullptr); } // Test that it converts properly to an 
arbitrary pointer type without warning
+_Static_assert(__nullptr == 0); // Test that its value matches that of NULL
+_Static_assert(_Generic(__typeof(__nullptr), int : 0, void * : 0, default : 
1)); // Test that it's type is not the same as what NULL would generally have.

>From 87c8b673863ccc7f17eeb2da02ab1c4a6f64de40 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:04:37 -0500
Subject: [PATCH 04/10] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 031c5d84e49f97..f234edc7920352 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,11 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+<<< HEAD
 - Macro ``__STDC_NO_THREADS__`` is no longer necessary for MSVC 2022 1939 and 
later.
+===
+- Added support for the ``__nullptr`` keyword. 
+>>> cfda1e8d3bf6 (Update ReleaseNotes.rst)
 
 C2y Feature Support
 ^^^

>From bb08c09d1a7c2b4ceac6e7868680e0111f531909 Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Sat, 18 Jan 2025 12:20:46 -0500
Subject: [PATCH 05/10] Update nullptr.c

Removed duplicate test
---
 clang/test/Sema/nullptr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/test/Sema/nullptr.c b/clang/test/Sema/nullptr.c
index bbe3d4c2ece7ff..b5d99ab89f5814 100644
--- a/clang/test/Sema/nullptr.c
+++ b/clang/test/Sema/nullptr.c
@@ -113,8 +113,5 @@ void foo(void *);
 void bar() { foo(__nullptr); }
 static_assert(nullptr == __nullptr);
 static_assert(_Generic(typeof(__nullptr), nullptr_t: true, default: false));
-
-void 

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-28 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/21] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-28 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/18] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-28 Thread Aidan Goldfarb via cfe-commits


@@ -649,15 +649,15 @@ namespace cwg241 { // cwg241: 9
 A::g<3>(b);
 C::f<3>(b);
 // expected-error@-1 {{no matching function for call to 'f'}}
-//   expected-note@#cwg241-C-f {{candidate template ignored: invalid 
explicitly-specified argument for template parameter 'T'}}
+//   expected-note@#cwg241-C-f {{candidate template ignored: invalid 
explicitly-specified argument for template parameter 'T': could not convert '3' 
from 'int' to class 'T' (expected a class, but got '3')}}

AidanGoldfarb wrote:

What you suggested is more like what GCC does, and I have updated it in my last 
patch, thanks!

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-28 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/20] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-28 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/19] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,37 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {

AidanGoldfarb wrote:

Would it be redundant to print the index in all cases, even when we can point 
to it with SourceRange? Would we prefer a message like: 
```
source.cpp:44:5: error: no matching function for call to 'case1'
   44 | case1<42>(42);
source.cpp:41:6: note: candidate template ignored: invalid explicitly-specified 
template argument: expected a type, but got value '42' (of type 'int')
   40 | template 
  |   ~~
   41 | void case1(T value) {}
  |  ^
```
(The above is what I have implemented and am planning to push)
over:

```
source.cpp:44:5: error: no matching function for call to 'case1'
   44 | case1<42>(42);
source.cpp:41:6: note: candidate template ignored: invalid explicitly-specified 
argument for 1st template parameter: expected a type, but got value '42' (of 
type 'int')
   40 | template 
  |   ~~
   41 | void case1(T value) {}
  |  ^
```

Although perhaps obvious, I am asking because `candidate template ignored: 
invalid explicitly-specified template argument: expected a type, but got value 
'42' (of type 'int')` on its own doesn't give us any location information.

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/24] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1cc..1456f34538bcc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b3..9edd3724cf53cd 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7d..6c437a52be21db 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.SecondA

[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits


@@ -11714,13 +11714,37 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
+if (ParamD->getDeclName()) {

AidanGoldfarb wrote:

Just added. A current message is like this:

```
template 
void case1(T value) {}

int main() {
case1<42>(42);
}
```

```
source.cpp:44:5: error: no matching function for call to 'case1'
   44 | case1<42>(42);
source.cpp:41:6: note: candidate template ignored: invalid explicitly-specified 
argument for template parameter 'T': expected a type, but got value '42' (of 
type 'int')
   40 | template 
  |   ~~
   41 | void case1(T value) {}
  |  ^
```
Perhaps it is a bit unclear having the highlight and caret on sequential lines, 
which both refer to the same function definition? If this format looks good I 
am happy to keep it, but I could foresee some confusion. 

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-29 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/122754

>From b6c576fb90362640b2fd4e41bd7f13dfee95d04d Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 13 Jan 2025 11:53:39 -0500
Subject: [PATCH 01/23] initial template arg fix push

---
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +-
 clang/include/clang/Sema/TemplateDeduction.h  |  5 ++
 clang/lib/Sema/SemaOverload.cpp   | 56 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  8 +++
 4 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8be4f946dce1ccb..1456f34538bcc07 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4871,8 +4871,8 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
 def note_ovl_candidate_explicit_arg_mismatch_named : Note<
-"candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"template argument deduction/substitution failed:" 
+"error: could not convert '%0' from %1 to %2">;
 def note_ovl_candidate_unsatisfied_constraints : Note<
 "candidate template ignored: constraints not satisfied%0">;
 def note_ovl_candidate_explicit_arg_mismatch_unnamed : Note<
diff --git a/clang/include/clang/Sema/TemplateDeduction.h 
b/clang/include/clang/Sema/TemplateDeduction.h
index 28b014fd84e4b35..9edd3724cf53cdb 100644
--- a/clang/include/clang/Sema/TemplateDeduction.h
+++ b/clang/include/clang/Sema/TemplateDeduction.h
@@ -250,6 +250,9 @@ class TemplateDeductionInfo {
   /// \brief The constraint satisfaction details resulting from the associated
   /// constraints satisfaction tests.
   ConstraintSatisfaction AssociatedConstraintsSatisfaction;
+
+  /// \brief Type supplied by user for deduction
+  TemplateArgument SuppliedType;
 };
 
 } // namespace sema
@@ -300,6 +303,8 @@ struct DeductionFailureInfo {
   TemplateDeductionResult getResult() const {
 return static_cast(Result);
   }
+
+  const TemplateArgument *getSuppliedType();
 };
 
 /// TemplateSpecCandidate - This is a generalization of OverloadCandidate
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 34c287926b1d7dc..6c437a52be21dbf 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -715,12 +715,18 @@ namespace {
   struct DFIParamWithArguments : DFIArguments {
 TemplateParameter Param;
   };
+
   // Structure used by DeductionFailureInfo to store template argument
   // information and the index of the problematic call argument.
   struct DFIDeducedMismatchArgs : DFIArguments {
 TemplateArgumentList *TemplateArgs;
 unsigned CallArgIndex;
   };
+
+  struct DFIParamWithArgumentsAndSuppliedType : DFIArguments {
+TemplateParameter Param;
+TemplateArgument SuppliedType;
+  };
   // Structure used by DeductionFailureInfo to store information about
   // unsatisfied constraints.
   struct CNSInfo {
@@ -736,8 +742,10 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 TemplateDeductionResult TDK,
 TemplateDeductionInfo &Info) {
   DeductionFailureInfo Result;
+
   Result.Result = static_cast(TDK);
   Result.HasDiagnostic = false;
+
   switch (TDK) {
   case TemplateDeductionResult::Invalid:
   case TemplateDeductionResult::InstantiationDepth:
@@ -749,10 +757,9 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 break;
 
   case TemplateDeductionResult::Incomplete:
-  case TemplateDeductionResult::InvalidExplicitArguments:
+// case TemplateDeductionResult::InvalidExplicitArguments:
 Result.Data = Info.Param.getOpaqueValue();
 break;
-
   case TemplateDeductionResult::DeducedMismatch:
   case TemplateDeductionResult::DeducedMismatchNested: {
 // FIXME: Should allocate from normal heap so that we can free this later.
@@ -777,6 +784,7 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
   case TemplateDeductionResult::IncompletePack:
 // FIXME: It's slightly wasteful to allocate two TemplateArguments for 
this.
   case TemplateDeductionResult::Inconsistent:
+
   case TemplateDeductionResult::Underqualified: {
 // FIXME: Should allocate from normal heap so that we can free this later.
 DFIParamWithArguments *Saved = new (Context) DFIParamWithArguments;
@@ -786,6 +794,16 @@ clang::MakeDeductionFailureInfo(ASTContext &Context,
 Result.Data = Saved;
 break;
   }
+  case TemplateDeductionResult::InvalidExplicitArguments: {
+DFIParamWithArgumentsAndSuppliedType *Saved =
+new (Context) DFIParamWithArgumentsAndSuppliedType;
+Saved->Param = Info.Param;
+Saved->FirstArg = Info.FirstArg;
+Saved->SecondArg = Info.S

  1   2   >