Skip to content
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

[Clang] Fix parsing of invalid type-requirement #98545

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

cor3ntin
Copy link
Contributor

A type-requirement cannot be an operator-function-id

Fixes #51868

A type-requirement cannot be an operator-function-id

Fixes llvm#51868
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 11, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

A type-requirement cannot be an operator-function-id

Fixes #51868


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+1)
  • (modified) clang/lib/Sema/SemaTemplate.cpp (+7)
  • (modified) clang/test/Parser/cxx-concepts-requires-clause.cpp (+9)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d5446f7fd92cc..b96ec100d4f5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1029,6 +1029,7 @@ Bug Fixes to C++ Support
 - Fixed a CTAD substitution bug involving type aliases that reference outer template parameters. (#GH94614).
 - Clang now correctly handles unexpanded packs in the template parameter list of a generic lambda expression
   (#GH48937)
+- Fix a crash when parsing an invalid type-requirement in a requires expression. (#GH51868)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 29d668e4fd8d7..8d77060246647 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -11698,6 +11698,13 @@ Sema::ActOnTypenameType(Scope *S, SourceLocation TypenameLoc,
     // Construct a dependent template specialization type.
     assert(DTN && "dependent template has non-dependent name?");
     assert(DTN->getQualifier() == SS.getScopeRep());
+
+    if (!DTN->isIdentifier()) {
+      Diag(TemplateIILoc, diag::err_template_id_not_a_type) << Template;
+      NoteAllFoundTemplates(Template);
+      return true;
+    }
+
     QualType T = Context.getDependentTemplateSpecializationType(
         ElaboratedTypeKeyword::Typename, DTN->getQualifier(),
         DTN->getIdentifier(), TemplateArgs.arguments());
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 5b5bc9ea978bf..13b4e8439882d 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -195,3 +195,12 @@ void F() {
 int a = []<int=0> requires requires { [](auto){}; } { return 0; }();
 
 } // namespace GH78524
+
+
+namespace GH51868 {
+template<auto L>
+concept C = requires {
+  typename decltype(L)::template operator()<int>;
+  // expected-error@-1 {{template name refers to non-type template 'decltype(L)::template operator ()'}}
+};
+}

Copy link
Contributor

@zyn0217 zyn0217 left a comment

Choose a reason for hiding this comment

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

Thanks! This makes sense to me.
(Curiously GCC and MSVC seem to defer the check until the evaluation. However, I don't think we have to do that in this patch anyway.)

clang/lib/Sema/SemaTemplate.cpp Show resolved Hide resolved
@cor3ntin
Copy link
Contributor Author

Thanks!

@cor3ntin cor3ntin merged commit 84bc0a9 into llvm:main Jul 12, 2024
11 checks passed
@cor3ntin cor3ntin deleted the corentin/gh51868 branch July 12, 2024 11:12
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
A type-requirement cannot be an operator-function-id

Fixes llvm#51868
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
Development

Successfully merging this pull request may close these issues.

Parser crash when checking templated lambda type in concept
3 participants