[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 20 21:13:27 PDT 2022
shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
shafik requested review of this revision.
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 an identifier.
This fixes: https://github.com/llvm/llvm-project/issues/57495
https://reviews.llvm.org/D134334
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseTentative.cpp
clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===================================================================
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -248,3 +248,11 @@
};
}
+
+namespace GH57495 {
+template <typename T> struct vector{};
+
+void f() {
+ GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
+}
+}
Index: clang/lib/Parse/ParseTentative.cpp
===================================================================
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1550,7 +1550,7 @@
if (getLangOpts().CPlusPlus17) {
if (TryAnnotateTypeOrScopeToken())
return TPResult::Error;
- if (Tok.isNot(tok::identifier))
+ if (NextToken().isNot(tok::identifier))
break;
}
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@
`Issue 53628 <https://github.com/llvm/llvm-project/issues/53628>`_
- The template arguments of a variable template being accessed as a
member will now be represented in the AST.
+- 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>`_
Improvements to Clang's diagnostics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134334.461784.patch
Type: text/x-patch
Size: 1610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220921/8c87836d/attachment.bin>
More information about the cfe-commits
mailing list