[clang] 061e3aa - [clang] require arg list in type specifiers using template kw (#94674)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 08:49:48 PDT 2024


Author: Erick Velez
Date: 2024-06-28T08:49:46-07:00
New Revision: 061e3aa08e35d2714f8bcda87aacf08e9e21771b

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

LOG: [clang] require arg list in type specifiers using template kw (#94674)

Require a template argument list after a name prefixed by the template
keyword in nested name specifiers. Addresses [CWG
96](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#96)
which was superseded by
[P1787](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html).

Followup to #80801.

Added: 
    

Modified: 
    clang/lib/Parse/Parser.cpp
    clang/test/Parser/cxx2a-concepts-requires-expr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 6d0cf7b174e50..71b87147e9a5f 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2060,9 +2060,19 @@ bool Parser::TryAnnotateTypeOrScopeToken(
       return true;
     }
 
+    bool TemplateKWPresent = false;
+    if (Tok.is(tok::kw_template)) {
+      ConsumeToken();
+      TemplateKWPresent = true;
+    }
+
     TypeResult Ty;
     if (Tok.is(tok::identifier)) {
-      // FIXME: check whether the next token is '<', first!
+      if (TemplateKWPresent && NextToken().isNot(tok::less)) {
+        Diag(Tok.getLocation(),
+             diag::missing_template_arg_list_after_template_kw);
+        return true;
+      }
       Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS,
                                      *Tok.getIdentifierInfo(),
                                      Tok.getLocation());

diff  --git a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
index 971591afb08db..5755844a323d2 100644
--- a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
+++ b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
@@ -83,7 +83,7 @@ bool r23 = requires { typename identity<T>::temp<T>; };
 template<typename T>
 bool r24 = requires {
     typename identity<T>::template temp<T>;
-    typename identity<T>::template temp; // expected-error{{expected an identifier or template-id after '::'}}
+    typename identity<T>::template temp; // expected-error{{template argument list is expected after a name prefixed by the template keyword}}
 };
 
 bool r25 = requires { ; };


        


More information about the cfe-commits mailing list