[clang] [Clang] Set the decl context to the instantiated constructor when instantiating the explicit specifier (PR #78053)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 13 21:55:31 PST 2024


https://github.com/LYP951018 updated https://github.com/llvm/llvm-project/pull/78053

>From ebd57b11fbce96a493c57d4c459baca6bcd6e9d2 Mon Sep 17 00:00:00 2001
From: letrec <liuyupei951018 at hotmail.com>
Date: Sun, 14 Jan 2024 00:59:23 +0800
Subject: [PATCH 1/3] add release notes

---
 clang/docs/ReleaseNotes.rst                |  3 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp   |  1 +
 clang/test/SemaCXX/cxx2a-explicit-bool.cpp | 18 ++++++++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5159cdc8a3bff..a7b954b9d4b09b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -848,6 +848,9 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_)
 
+- Fixed the handling of concepts with lambda expression constraints in explicit specifiers. 
+  Fixes: (`#67058 <https://github.com/llvm/llvm-project/issues/67058>`_)
+
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 <https://github.com/llvm/llvm-project/issues/73112>`_)
 
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 699e0985e595b6..1ad6cab93614af 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3585,6 +3585,7 @@ static Sema::TemplateDeductionResult instantiateExplicitSpecifierDeferred(
   if (Inst.isInvalid())
     return Sema::TDK_InstantiationDepth;
   Sema::SFINAETrap Trap(S);
+  Sema::ContextRAII InstantiatedContext(S, Specialization);
   const ExplicitSpecifier InstantiatedES =
       S.instantiateExplicitSpecifier(SubstArgs, ES);
   if (InstantiatedES.isInvalid() || Trap.hasErrorOccurred()) {
diff --git a/clang/test/SemaCXX/cxx2a-explicit-bool.cpp b/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
index 9fdc059493aacb..7ee58da0a175b8 100644
--- a/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ b/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -743,3 +743,21 @@ struct S {
   explicit(1L) S(char, char, char);
 };
 } // namespace P1401
+
+#if __cplusplus > 201703L
+namespace GH67058 {
+template <class T>
+concept Q = requires(T t) { [](int *) {}(t); };
+struct A {
+  template <class T> explicit(Q<T>) A(T);
+};
+A a = 1;
+
+struct B { // expected-note+ {{candidate constructor}}
+  template <class T>
+  explicit(requires(T t) { [](int *) {}(t); })
+      B(T); // expected-note {{explicit constructor is not a candidate}}
+};
+B b = new int; // expected-error {{no viable conversion}}
+} // namespace GH67058
+#endif
\ No newline at end of file

>From d9584acd62b088e5696cb5c63ba39ecbd173a1b5 Mon Sep 17 00:00:00 2001
From: letrec <liuyupei951018 at hotmail.com>
Date: Sun, 14 Jan 2024 01:57:04 +0800
Subject: [PATCH 2/3] remove trailing spaces

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a7b954b9d4b09b..46a15abfb1cc7c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -848,7 +848,7 @@ Bug Fixes to C++ Support
   completes (except deduction guides). Fixes:
   (`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_)
 
-- Fixed the handling of concepts with lambda expression constraints in explicit specifiers. 
+- Fixed the handling of concepts with lambda expression constraints in explicit specifiers.
   Fixes: (`#67058 <https://github.com/llvm/llvm-project/issues/67058>`_)
 
 - Fix crash when parsing nested requirement. Fixes:

>From 756368a26f36a5d7a3fcfd73c87841d9f75d141d Mon Sep 17 00:00:00 2001
From: letrec <liuyupei951018 at hotmail.com>
Date: Sun, 14 Jan 2024 13:55:17 +0800
Subject: [PATCH 3/3] add linebreak at end

---
 clang/test/SemaCXX/cxx2a-explicit-bool.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/cxx2a-explicit-bool.cpp b/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
index 7ee58da0a175b8..ceb347fff85600 100644
--- a/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ b/clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -760,4 +760,4 @@ struct B { // expected-note+ {{candidate constructor}}
 };
 B b = new int; // expected-error {{no viable conversion}}
 } // namespace GH67058
-#endif
\ No newline at end of file
+#endif



More information about the cfe-commits mailing list