[clang] 7aa3270 - [clang] Add cxx scope if needed for requires clause.

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 26 01:16:20 PDT 2022


Author: Luke Nihlen
Date: 2022-08-26T10:15:54+02:00
New Revision: 7aa3270622f495ce1209aeca83a3b216889ccab4

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

LOG: [clang] Add cxx scope if needed for requires clause.

Fixes issue #55216.

Patch by Luke Nihlen! (luken at google.com, luken-google@)

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D132503

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseTemplate.cpp
    clang/test/Parser/cxx-concepts-requires-clause.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f4747ddd1199..d3b255ace6bd2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -171,6 +171,8 @@ C++20 Feature Support
   Note: The handling of deleted functions is not yet compliant, as Clang
   does not implement `DR1496 <https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1496>`_
   and `DR1734 <https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1734>`_.
+- Class member variables are now in scope when parsing requires clauses. Fixes
+  `GH55216 <https://github.com/llvm/llvm-project/issues/55216>`_.
 
 
 

diff  --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index e32ea6003b84e..55eb3cb6399b5 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -289,8 +289,14 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
 
   LateParsedAttrList LateParsedAttrs(true);
   if (DeclaratorInfo.isFunctionDeclarator()) {
-    if (Tok.is(tok::kw_requires))
+    if (Tok.is(tok::kw_requires)) {
+      CXXScopeSpec &ScopeSpec = DeclaratorInfo.getCXXScopeSpec();
+      DeclaratorScopeObj DeclScopeObj(*this, ScopeSpec);
+      if (ScopeSpec.isValid() &&
+          Actions.ShouldEnterDeclaratorScope(getCurScope(), ScopeSpec))
+        DeclScopeObj.EnterDeclaratorScope();
       ParseTrailingRequiresClause(DeclaratorInfo);
+    }
 
     MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
   }

diff  --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index db8f167ba9755..e4bdd28f61ec1 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -12,6 +12,7 @@ struct A {
   struct AA;
   enum E : int;
   static int x;
+  static constexpr int z = 16;
 
   template <typename> requires true
   void Mfoo();
@@ -24,6 +25,8 @@ struct A {
 
   template <typename TT> requires true
   using MQ = M<TT>;
+
+  constexpr int bazz() requires (z == 16);
 };
 
 template <typename T> requires (!0)
@@ -56,6 +59,9 @@ int x = 0;
 template <typename T> requires true
 using Q = A<T>;
 
+template<typename T> requires (!0)
+constexpr int A<T>::bazz() requires (z == 16) { return z; }
+
 struct C {
   template <typename> requires true
   void Mfoo();


        


More information about the cfe-commits mailing list