Skip to content

Commit

Permalink
[Clang] Fix parsing of invalid type-requirement (#98545)
Browse files Browse the repository at this point in the history
A type-requirement cannot be an operator-function-id

Fixes #51868
  • Loading branch information
cor3ntin committed Jul 12, 2024
1 parent 2c2148d commit 84bc0a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,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
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11690,6 +11690,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());
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Parser/cxx-concepts-requires-clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()'}}
};
}

0 comments on commit 84bc0a9

Please sign in to comment.