[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-07 Thread Krystian Stasiowski via cfe-commits

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-07 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90760

>From e5e0f25de3307128914b6fcfc9223b389e7b6438 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/5] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e442282717..026ce6db1c8eb 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3509,23 +3509,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 0..cf6d17fc51ac9
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From 3e31517090dd899c9161406ad38626ecaca8c787 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/5] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 24 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++---
 clang/test/CXX/drs/dr13xx.cpp | 13 --
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--
 clang/test/SemaTemplate/temp_arg_type.cpp | 10 
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461..c8049ae581f84 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,12 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9641,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9652,21 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+  

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-07 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90760

>From e5e0f25de3307128914b6fcfc9223b389e7b6438 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/5] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e4422827173..026ce6db1c8eb9 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3509,23 +3509,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 00..cf6d17fc51ac95
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From 3e31517090dd899c9161406ad38626ecaca8c787 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/5] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 24 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++---
 clang/test/CXX/drs/dr13xx.cpp | 13 --
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--
 clang/test/SemaTemplate/temp_arg_type.cpp | 10 
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461d..c8049ae581f843 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,12 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9641,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9652,21 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

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

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

LGTM

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-06 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90760

>From a30530b4de31fab70911cb7b51e7a7e274fd2a38 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/4] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e4422827173..026ce6db1c8eb9 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3509,23 +3509,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 00..cf6d17fc51ac95
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From 9172000c589d7235e0e93d22b10017d25b3df1fd Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/4] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 24 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++---
 clang/test/CXX/drs/dr13xx.cpp | 13 --
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--
 clang/test/SemaTemplate/temp_arg_type.cpp | 10 
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461d..c8049ae581f843 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,12 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9641,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9652,21 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

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

https://github.com/Endilll commented:

DR tests changes LGTM

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

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

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

LGTM.  I want @Endilll to confirm the DR test looks right though.

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-06 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90760

>From a30530b4de31fab70911cb7b51e7a7e274fd2a38 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/3] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 9f9e4422827173..026ce6db1c8eb9 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3509,23 +3509,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 00..cf6d17fc51ac95
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From 9172000c589d7235e0e93d22b10017d25b3df1fd Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/3] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 24 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++---
 clang/test/CXX/drs/dr13xx.cpp | 13 --
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--
 clang/test/SemaTemplate/temp_arg_type.cpp | 10 
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461d..c8049ae581f843 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,12 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9641,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9652,21 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-06 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

Ping @erichkeane 

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread Krystian Stasiowski via cfe-commits

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread Krystian Stasiowski via cfe-commits

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

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

https://github.com/Endilll commented:

Changes to DR tests look good to me.

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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7cbaaed63612fe6446355c5ffe33ddd57578b929 
2bc18f45560f607a09c756bb9ebca0b7ad5d1bb4 -- 
clang/test/CXX/temp/temp.deduct/p7.cpp clang/lib/Sema/SemaInit.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp clang/test/CXX/drs/dr13xx.cpp 
clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp 
clang/test/SemaTemplate/temp_arg_type.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2c1c7affbc..c8049ae581 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6578,8 +6578,10 @@ void InitializationSequence::InitializeFrom(Sema ,
   } else if (ICS.isBad()) {
 if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-else if (DeclAccessPair Found; Initializer->getType() == 
Context.OverloadTy &&
-!S.ResolveAddressOfOverloadedFunction(Initializer, DestType, 
/*Complain=*/false, Found))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9654,8 +9656,10 @@ bool InitializationSequence::Diagnose(Sema ,
 if (OnlyArg->getType() == S.Context.OverloadTy) {
   DeclAccessPair Found;
   if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
-  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false, Found)) 
{
-if (Expr *Resolved = S.FixOverloadedFunctionReference(OnlyArg, Found, 
FD).get())
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+  Found)) {
+if (Expr *Resolved =
+S.FixOverloadedFunctionReference(OnlyArg, Found, FD).get())
   OnlyArg = Resolved;
   }
 }

``




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


[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/90760

>From 5086c9801842b22dbc99393d52a02f35d1fcfdfc Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/2] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e93f7bd842e444..1f67cf0dd3f6d2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3414,23 +3414,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 00..cf6d17fc51ac95
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From f914b16a23e39b1f1e5f4999bac34e8af7a367f5 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/2] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 24 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++---
 clang/test/CXX/drs/dr13xx.cpp | 13 --
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--
 clang/test/SemaTemplate/temp_arg_type.cpp | 10 
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461d..c8049ae581f843 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,12 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found;
+ Initializer->getType() == Context.OverloadTy &&
+ !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
+   /*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9641,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9652,21 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false,
+

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

[[temp.deduct.general] p6](eel.is/c++draft/temp.deduct.general#6) 
states:
 At certain points in the template argument deduction process it is 
necessary to take a function type that makes use of template parameters and 
replace those template parameters with the corresponding template arguments.
This is done at the beginning of template argument deduction when any 
explicitly specified template arguments are substituted into the function type, 
and again at the end of template argument deduction when any template arguments 
that were deduced or obtained from default arguments are substituted.

[[temp.deduct.general] p7](eel.is/c++draft/temp.deduct.general#7) goes 
on to say:
 The _deduction substitution loci_ are
 - the function type outside of the _noexcept-specifier_,
 - the explicit-specifier,
 - the template parameter declarations, and
 - the template argument list of a partial specialization

  The substitution occurs in all types and expressions that are used in the 
deduction substitution loci. [...]

Currently, `Sema::SubstituteExplicitTemplateArguments` will substitute into the 
_noexcept-specifier_ when deducing template arguments from a function 
declaration or when deducing template arguments for taking the address of a 
function template (and the substitution is treated as happening in a SFINAE 
context). This behavior is incorrect ([note 
4](http://eel.is/c++draft/temp.deduct.general#note-4) says as much), and this 
patch corrects it by deferring all substitution into the _noexcept-specifier_ 
until it is instantiated. 

As part of the necessary changes to make this patch work, the instantiation of 
the exception specification of a function template specialization when taking 
the address of a function template is changed to only occur for the function 
selected by overload resolution per [[except.spec] 
p13.1](http://eel.is/c++draft/except.spec#13.1) (as opposed to being 
instantiated for every candidate).

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


6 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+14-6) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+2-26) 
- (modified) clang/test/CXX/drs/dr13xx.cpp (+5-8) 
- (added) clang/test/CXX/temp/temp.deduct/p7.cpp (+14) 
- (modified) clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp (+2-2) 
- (modified) clang/test/SemaTemplate/temp_arg_type.cpp (+4-6) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7d9eaf6720461d..2c1c7affbc13a4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6576,12 +6576,10 @@ void InitializationSequence::InitializeFrom(Sema ,
 
 AddPassByIndirectCopyRestoreStep(DestType, ShouldCopy);
   } else if (ICS.isBad()) {
-DeclAccessPair dap;
-if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer)) {
+if (isLibstdcxxPointerReturnFalseHack(S, Entity, Initializer))
   AddZeroInitializationStep(Entity.getType());
-} else if (Initializer->getType() == Context.OverloadTy &&
-   !S.ResolveAddressOfOverloadedFunction(Initializer, DestType,
- false, dap))
+else if (DeclAccessPair Found; Initializer->getType() == 
Context.OverloadTy &&
+!S.ResolveAddressOfOverloadedFunction(Initializer, DestType, 
/*Complain=*/false, Found))
   SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
 else if (Initializer->getType()->isFunctionType() &&
  isExprAnUnaddressableFunction(S, Initializer))
@@ -9641,6 +9639,8 @@ bool InitializationSequence::Diagnose(Sema ,
   if (!Failed())
 return false;
 
+  QualType DestType = Entity.getType();
+
   // When we want to diagnose only one element of a braced-init-list,
   // we need to factor it out.
   Expr *OnlyArg;
@@ -9650,11 +9650,19 @@ bool InitializationSequence::Diagnose(Sema ,
   OnlyArg = List->getInit(0);
 else
   OnlyArg = Args[0];
+
+if (OnlyArg->getType() == S.Context.OverloadTy) {
+  DeclAccessPair Found;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  OnlyArg, DestType.getNonReferenceType(), /*Complain=*/false, Found)) 
{
+if (Expr *Resolved = S.FixOverloadedFunctionReference(OnlyArg, Found, 
FD).get())
+  OnlyArg = Resolved;
+  }
+}
   }
   else
 OnlyArg = nullptr;
 
-  QualType DestType = Entity.getType();
   switch (Failure) {
   case FK_TooManyInitsForReference:
 // FIXME: Customize for the initialized entity?
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e93f7bd842e444..fc8a645e733926 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1231,11 +1231,11 @@ bool Sema::isSameOrCompatibleFunctionType(QualType P, 
QualType A) {
   // Noreturn and noexcept 

[clang] [Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function (PR #90760)

2024-05-01 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/90760

[[temp.deduct.general] p6](eel.is/c++draft/temp.deduct.general#6) states:
> At certain points in the template argument deduction process it is necessary 
> to take a function type that makes use of template parameters and replace 
> those template parameters with the corresponding template arguments.
This is done at the beginning of template argument deduction when any 
explicitly specified template arguments are substituted into the function type, 
and again at the end of template argument deduction when any template arguments 
that were deduced or obtained from default arguments are substituted.

[[temp.deduct.general] p7](eel.is/c++draft/temp.deduct.general#7) goes on to 
say:
> The _deduction substitution loci_ are
> - the function type outside of the _noexcept-specifier_,
> - the explicit-specifier,
> - the template parameter declarations, and
> - the template argument list of a partial specialization
>
>  The substitution occurs in all types and expressions that are used in the 
> deduction substitution loci. [...]

Currently, `Sema::SubstituteExplicitTemplateArguments` will substitute into the 
_noexcept-specifier_ when deducing template arguments from a function 
declaration or when deducing template arguments for taking the address of a 
function template (and the substitution is treated as happening in a SFINAE 
context). This behavior is incorrect ([note 
4](http://eel.is/c++draft/temp.deduct.general#note-4) says as much), and this 
patch corrects it by deferring all substitution into the _noexcept-specifier_ 
until it is instantiated. 

As part of the necessary changes to make this patch work, the instantiation of 
the exception specification of a function template specialization when taking 
the address of a function template is changed to only occur for the function 
selected by overload resolution per [[except.spec] 
p13.1](http://eel.is/c++draft/except.spec#13.1) (as opposed to being 
instantiated for every candidate).

>From 5086c9801842b22dbc99393d52a02f35d1fcfdfc Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 10:54:12 -0400
Subject: [PATCH 1/2] [Clang][Sema] Explicit template arguments are not
 substituted into the exception specification of a function

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 17 -
 clang/test/CXX/temp/temp.deduct/p7.cpp   | 14 ++
 2 files changed, 14 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/CXX/temp/temp.deduct/p7.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e93f7bd842e444..1f67cf0dd3f6d2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3414,23 +3414,6 @@ TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
   if (FunctionType) {
 auto EPI = Proto->getExtProtoInfo();
 EPI.ExtParameterInfos = ExtParamInfos.getPointerOrNull(ParamTypes.size());
-
-// In C++1z onwards, exception specifications are part of the function 
type,
-// so substitution into the type must also substitute into the exception
-// specification.
-SmallVector ExceptionStorage;
-if (getLangOpts().CPlusPlus17 &&
-SubstExceptionSpec(
-Function->getLocation(), EPI.ExceptionSpec, ExceptionStorage,
-getTemplateInstantiationArgs(
-FunctionTemplate, nullptr, /*Final=*/true,
-/*Innermost=*/SugaredExplicitArgumentList->asArray(),
-/*RelativeToPrimary=*/false,
-/*Pattern=*/nullptr,
-/*ForConstraintInstantiation=*/false,
-/*SkipForSpecialization=*/true)))
-  return TemplateDeductionResult::SubstitutionFailure;
-
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
   Function->getLocation(),
   Function->getDeclName(),
diff --git a/clang/test/CXX/temp/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.deduct/p7.cpp
new file mode 100644
index 00..cf6d17fc51ac95
--- /dev/null
+++ b/clang/test/CXX/temp/temp.deduct/p7.cpp
@@ -0,0 +1,14 @@
+// RUN:  %clang_cc1 -verify %s
+
+struct A {
+  static constexpr bool x = true;
+};
+
+template
+void f(T, U) noexcept(T::x);
+
+template
+void f(T, U*) noexcept(T::y); // expected-error {{no member named 'y' in 'A'}}
+
+template<>
+void f(A, int*); // expected-note {{in instantiation of exception 
specification}}

>From 2bc18f45560f607a09c756bb9ebca0b7ad5d1bb4 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 1 May 2024 14:14:28 -0400
Subject: [PATCH 2/2] [FOLD]

---
 clang/lib/Sema/SemaInit.cpp   | 20 +--
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 11 ++
 clang/test/CXX/drs/dr13xx.cpp | 13 +---
 .../SemaCXX/cxx1z-noexcept-function-type.cpp  |  4 ++--