[clang] c48442c - PR45207: Fix crash if constrained-type-specifier annotation forms a

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 17 13:18:36 PDT 2020


Author: Richard Smith
Date: 2020-03-17T13:18:23-07:00
New Revision: c48442c9f38836c69d7b90dddf27eea549a4f14c

URL: https://github.com/llvm/llvm-project/commit/c48442c9f38836c69d7b90dddf27eea549a4f14c
DIFF: https://github.com/llvm/llvm-project/commit/c48442c9f38836c69d7b90dddf27eea549a4f14c.diff

LOG: PR45207: Fix crash if constrained-type-specifier annotation forms a
template_id annotation when parsing a type.

Added: 
    clang/test/SemaTemplate/undeclared-template.cpp

Modified: 
    clang/lib/Parse/ParseDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 09d1732739b8..17298dad4564 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3407,7 +3407,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
       if (!TypeRep) {
         if (TryAnnotateTypeConstraint())
           goto DoneWithDeclSpec;
-        if (isTypeConstraintAnnotation())
+        if (Tok.isNot(tok::identifier))
           continue;
         if (Tok.is(tok::annot_template_id))
           // Might have been annotated by TryAnnotateTypeConstraint.

diff  --git a/clang/test/SemaTemplate/undeclared-template.cpp b/clang/test/SemaTemplate/undeclared-template.cpp
new file mode 100644
index 000000000000..fccc29deea25
--- /dev/null
+++ b/clang/test/SemaTemplate/undeclared-template.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+template<typename T> notdefined<T::any> PR45207; // expected-error {{no template named 'notdefined'}}
+
+// FIXME: We don't disambiguate this as an undeclared template-id even though there's nothing else it could be.
+template<typename T> int var_template(notdefined<T::any>); // expected-error {{undeclared identifier 'notdefined'}} expected-error {{expected expression}}
+
+// FIXME: We don't disambiguate this as a function template even though it can't be a variable template due to the ', int'.
+template<typename T> int fn_template(notdefined<T::any>, int); // expected-error {{undeclared identifier 'notdefined'}} expected-error {{expected expression}} expected-error {{expected '('}}


        


More information about the cfe-commits mailing list