[PATCH] D150001: [clang] Fix initializer_list matching failures with modules

Alan Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 9 10:32:01 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1d35f04c6cb: [clang] Fix initializer_list matching failures with modules (authored by ayzhao).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150001/new/

https://reviews.llvm.org/D150001

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Modules/match_initializer_list.cpp


Index: clang/test/Modules/match_initializer_list.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/match_initializer_list.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -x c++ -fmodules -fmodules-cache-path=%t \
+// RUN:     -I %S/Inputs/initializer_list \
+// RUN:     -fmodule-map-file=%S/Inputs/initializer_list/direct.modulemap \
+// RUN:     %s -verify
+
+// expected-no-diagnostics
+
+class C {
+  public:
+  virtual ~C() {}
+};
+
+#include "Inputs/initializer_list/direct.h"
+
+void takesInitList(std::initializer_list<int>);
+
+void passesInitList() { takesInitList({0}); }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11567,6 +11567,10 @@
         &PP.getIdentifierTable().get("std"),
         /*PrevDecl=*/nullptr, /*Nested=*/false);
     getStdNamespace()->setImplicit(true);
+    // We want the created NamespaceDecl to be available for redeclaration
+    // lookups, but not for regular name lookups.
+    Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+    getStdNamespace()->clearIdentifierNamespace();
   }
 
   return getStdNamespace();
Index: clang/include/clang/AST/DeclBase.h
===================================================================
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -1172,6 +1172,12 @@
     }
   }
 
+  /// Clears the namespace of this declaration.
+  ///
+  /// This is useful if we want this declaration to be available for
+  /// redeclaration lookup but otherwise hidden for ordinary name lookups.
+  void clearIdentifierNamespace() { IdentifierNamespace = 0; }
+
   enum FriendObjectKind {
     FOK_None,      ///< Not a friend object.
     FOK_Declared,  ///< A friend of a previously-declared entity.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150001.520746.patch
Type: text/x-patch
Size: 1913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230509/ae50437f/attachment.bin>


More information about the cfe-commits mailing list