llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)

<details>
<summary>Changes</summary>

At best this would cause cascading errors, but the example given in the bug 
report shows a case where we are breaking an assumed invariant due to the 
invalid NTTP. This patch just skips early and treats these as non-matching if 
either is invalid.

Fixes: #<!-- -->208658

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+2) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+7) 
- (modified) clang/test/CXX/temp/temp.param/p10-2a.cpp (+7) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 07e9d4a554dd1..8f8cbf0342560 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -145,6 +145,8 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 #### Bug Fixes to C++ Support
 
+-Fixed an issue where we tried to compare invalid NTTPs for variable 
declarations, which ended up in hitting an assertion with a constrained 
non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
+
 #### Bug Fixes to AST Handling
 
 - Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7286a0c2f6fbf..8a778df4a794f 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8281,6 +8281,13 @@ static bool MatchTemplateParameterKind(
     if (Kind != Sema::TPL_TemplateTemplateParmMatch ||
         (!OldNTTP->getType()->isDependentType() &&
          !NewNTTP->getType()->isDependentType())) {
+
+      // Matching against an invalid declaration is going to be rife with
+      // errors, particularly when `getUnconstrainedType` isn't really valid
+      // there. Just treat these as otherwise invalid.
+      if (OldNTTP->isInvalidDecl() || NewNTTP->isInvalidDecl())
+        return false;
+
       // C++20 [temp.over.link]p6:
       //   Two [non-type] template-parameters are equivalent [if] they have
       //   equivalent types ignoring the use of type-constraints for
diff --git a/clang/test/CXX/temp/temp.param/p10-2a.cpp 
b/clang/test/CXX/temp/temp.param/p10-2a.cpp
index c0406f88db5f3..c915afd97aee9 100644
--- a/clang/test/CXX/temp/temp.param/p10-2a.cpp
+++ b/clang/test/CXX/temp/temp.param/p10-2a.cpp
@@ -141,3 +141,10 @@ using j2 = J<'a', nullptr>;
 template<OneOf<char, int> auto &x>
 // expected-error@-1 {{constrained placeholder types other than simple 'auto' 
on non-type template parameters not supported yet}}
 using K = int;
+
+namespace GH208658 {
+template <class> concept C = true;
+template <auto &x> using A = int;
+template <C auto &x> using A = int;
+// expected-error@-1 {{constrained placeholder types other than simple 'auto' 
on non-type template parameters not supported yet}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/209893
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to