Skip to content

Commit

Permalink
[Clang] Fix crash in isCXXDeclarationSpecifier when attempting to ann…
Browse files Browse the repository at this point in the history
…otate template name

When attempting to decide if in C++17 a type template for class template
argument deduction and the code is ill-formed the condition to break is
checking the current token is an identifier when it should be checking
if the next token is not ::.

This fixes: #57495
#63052

Differential Revision: https://reviews.llvm.org/D134334
  • Loading branch information
shafik committed Jun 29, 2023
1 parent 40cdb22 commit d1fcce9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ Bug Fixes in This Version
(`#48512 <https://github.com/llvm/llvm-project/issues/48512>`_).
- Fixed a failing assertion when parsing incomplete destructor.
(`#63503 <https://github.com/llvm/llvm-project/issues/63503>`_)
- Fix C++17 mode assert when parsing malformed code and the compiler is
attempting to see if it could be type template for class template argument
deduction. This fixes
(`Issue 57495 <https://github.com/llvm/llvm-project/issues/57495>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Parse/ParseTentative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,10 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
if (getLangOpts().CPlusPlus17) {
if (TryAnnotateTypeOrScopeToken())
return TPResult::Error;
if (Tok.isNot(tok::identifier))
// If we annotated then the current token should not still be ::
// FIXME we may want to also check for tok::annot_typename but
// currently don't have a test case.
if (Tok.isNot(tok::annot_cxxscope))
break;
}

Expand Down
8 changes: 8 additions & 0 deletions clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,11 @@ struct A2 {
};

}

namespace GH57495 {
template <typename T> struct vector{};

void f() {
GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
}
}

0 comments on commit d1fcce9

Please sign in to comment.