Skip to content

[Clang][Sema] fix deducing auto& from const int in template parameters is impossible in partial specializations #79733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

jcsxky
Copy link
Contributor

@jcsxky jcsxky commented Jan 28, 2024

Fix issue
AutoType is possible cv qualified.

Also fixes #75843.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2024

@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)

Changes

Fix issue
AutoType is possible cv qualified.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1)
  • (added) clang/test/SemaTemplate/PR77189.cpp (+22)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 25e58f7bdd953d1..f08577febcd3e80 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -649,6 +649,7 @@ static bool IsPossiblyOpaquelyQualifiedTypeInternal(const Type *T) {
   case Type::PackIndexing:
   case Type::UnresolvedUsing:
   case Type::TemplateTypeParm:
+  case Type::Auto:
     return true;
 
   case Type::ConstantArray:
diff --git a/clang/test/SemaTemplate/PR77189.cpp b/clang/test/SemaTemplate/PR77189.cpp
new file mode 100644
index 000000000000000..dd2e4511a02cf70
--- /dev/null
+++ b/clang/test/SemaTemplate/PR77189.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+struct false_type {
+	static constexpr bool value = false;
+};
+
+struct true_type {
+	static constexpr bool value = true;
+};
+
+template <auto& Value, int>
+struct test : false_type {};
+
+template <auto& Value>
+struct test<Value, 0> : true_type {};
+
+int main() {
+    static constexpr int v = 42;
+    static_assert(test<v, 0>::value);
+}
\ No newline at end of file

@jcsxky jcsxky force-pushed the fix_deduce_auto_incorrect branch from 35662b8 to 9834d06 Compare January 28, 2024 07:22
@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 28, 2024

Oh wow, thanks for this fix!
It will need a Changelog entry.

Does it fixes any of these issues? #68885

@jcsxky
Copy link
Contributor Author

jcsxky commented Jan 28, 2024

Oh wow, thanks for this fix! It will need a Changelog entry.

Does it fixes any of these issues? #68885

This patch can't fix #68885. I have looked into the code and the root cause maybe different (probably relate to ExprConst, I'm not sure). Need more work on that issue.

…s is impossible in partial specializations
@jcsxky jcsxky force-pushed the fix_deduce_auto_incorrect branch from a77a2bf to af0b28a Compare January 28, 2024 13:33
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
3 participants