-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Conversation
A type-requirement cannot be an operator-function-id Fixes llvm#51868
@llvm/pr-subscribers-clang Author: cor3ntin (cor3ntin) ChangesA type-requirement cannot be an operator-function-id Fixes #51868 Full diff: https://github.com/llvm/llvm-project/pull/98545.diff 3 Files Affected:
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 ()'}}
+};
+}
|
There was a problem hiding this 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.)
Thanks! |
A type-requirement cannot be an operator-function-id Fixes llvm#51868
A type-requirement cannot be an operator-function-id
Fixes #51868