diff options
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp | 39 |
3 files changed, 42 insertions, 1 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a541d39..6802c0c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -810,6 +810,8 @@ Bug Fixes to C++ Support - Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda captures at the end of a full expression. (#GH115931) - Clang no longer rejects deleting a pointer of incomplete enumeration type. (#GH99278) +- Fixed recognition of ``std::initializer_list`` when it's surrounded with ``extern "C++"`` and exported + out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index b2c5bb2..c5a72cf 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -11931,7 +11931,7 @@ bool Sema::isStdInitializerList(QualType Ty, QualType *Element) { if (TemplateClass->getIdentifier() != &PP.getIdentifierTable().get("initializer_list") || !getStdNamespace()->InEnclosingNamespaceSetOf( - TemplateClass->getDeclContext())) + TemplateClass->getNonTransparentDeclContext())) return false; // This is a template called std::initializer_list, but is it the right // template? diff --git a/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp b/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp new file mode 100644 index 0000000..e2c796f --- /dev/null +++ b/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp @@ -0,0 +1,39 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/std.cppm -emit-module-interface -o %t/std.pcm +// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -fprebuilt-module-path=%t -emit-module-interface -o %t/mod.pcm +// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -verify %t/main.cpp + +//--- std.cppm +export module std; + +extern "C++" { + namespace std { + export template <class E> + class initializer_list { + const E* _1; + const E* _2; + }; + } +} + +//--- mod.cppm +export module mod; + +import std; + +export struct A { + void func(std::initializer_list<int>) {} +}; + +//--- main.cpp +// expected-no-diagnostics +import std; +import mod; + +int main() { + A{}.func({1,1}); + return 0; +} |