[clang] fa596fb - Fix a failed assertion on an invalid typename requirement

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 18 08:59:19 PST 2022


Author: Aaron Ballman
Date: 2022-01-18T11:59:08-05:00
New Revision: fa596fb0779ae9029edbcff80ff95e9d1a816206

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

LOG: Fix a failed assertion on an invalid typename requirement

The parsing code for a typename requirement currently asserts when
given something which is not a valid type-requirement
(http://eel.is/c++draft/expr.prim.req.type#nt:type-requirement). This
removes the assertion to continue on to the proper diagnostic.

This resolves PR53057.

Note that in that PR, it is using _BitInt(N) as a dependent type name.
This patch does not attempt to support that as it is not clear that is
a valid type requirement (it does not match the grammar production for
one). The workaround in the PR, however, is definitely valid and works
as expected.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index cd600c4247a7..2d38891c723f 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3589,7 +3589,7 @@ ExprResult Parser::ParseRequiresExpression() {
 
           // We need to consume the typename to allow 'requires { typename a; }'
           SourceLocation TypenameKWLoc = ConsumeToken();
-          if (TryAnnotateCXXScopeToken()) {
+          if (TryAnnotateOptionalCXXScopeToken()) {
             TPA.Commit();
             SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
             break;

diff  --git a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
index d22f21b786f4..d3f46c163ffd 100644
--- a/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
+++ b/clang/test/Parser/cxx2a-concepts-requires-expr.cpp
@@ -144,3 +144,18 @@ bool r40 = requires { requires (int i) { i; }; };
 
 bool r41 = requires { requires (); };
 // expected-error at -1 {{expected expression}}
+
+bool r42 = requires { typename long; }; // expected-error {{expected a qualified name after 'typename'}}
+
+template <int N>
+requires requires {
+ typename _BitInt(N); // expected-error {{expected a qualified name after 'typename'}}
+} using r43 = void;
+
+template <int N>
+using BitInt = _BitInt(N);
+
+template <int N>
+requires requires {
+ typename BitInt<N>; // ok
+} using r44 = void;


        


More information about the cfe-commits mailing list