Skip to content

Commit f1b37b6

Browse files
Artsiom Drapuntru
Artsiom Drapun
authored andcommitted
Fix std::initializer_list recognition if it's exported out of a module
- Add implementation - Add a regression test - Add release notes
1 parent 510be23 commit f1b37b6

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,8 @@ Bug Fixes to C++ Support
11231123
- Fixed assertion failure by skipping the analysis of an invalid field declaration. (#GH99868)
11241124
- Fix an issue with dependent source location expressions (#GH106428), (#GH81155), (#GH80210), (#GH85373)
11251125
- Fix handling of ``_`` as the name of a lambda's init capture variable. (#GH107024)
1126-
1126+
- Fixed recognition of ``std::initializer_list`` when it's surrounded with ``extern "C++"`` and exported
1127+
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
11271128

11281129
Bug Fixes to AST Handling
11291130
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11919,7 +11919,7 @@ bool Sema::isStdInitializerList(QualType Ty, QualType *Element) {
1191911919
if (TemplateClass->getIdentifier() !=
1192011920
&PP.getIdentifierTable().get("initializer_list") ||
1192111921
!getStdNamespace()->InEnclosingNamespaceSetOf(
11922-
TemplateClass->getDeclContext()))
11922+
TemplateClass->getNonTransparentDeclContext()))
1192311923
return false;
1192411924
// This is a template called std::initializer_list, but is it the right
1192511925
// template?
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/std.cppm -emit-module-interface -o %t/std.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/mod.cppm -fprebuilt-module-path=%t -emit-module-interface -o %t/mod.pcm
7+
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -verify %t/main.cpp
8+
9+
//--- std.cppm
10+
export module std;
11+
12+
extern "C++" {
13+
namespace std {
14+
export template <class E>
15+
class initializer_list {
16+
const E* _1;
17+
const E* _2;
18+
};
19+
}
20+
}
21+
22+
//--- mod.cppm
23+
export module mod;
24+
25+
import std;
26+
27+
export struct A {
28+
void func(std::initializer_list<int>) {}
29+
};
30+
31+
//--- main.cpp
32+
// expected-no-diagnostics
33+
import std;
34+
import mod;
35+
36+
int main() {
37+
A{}.func({1,1});
38+
return 0;
39+
}

0 commit comments

Comments
 (0)