llvm-project/clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp
jijjijj 9f1e9f682d
[C++20][modules] Fix std::initializer_list recognition if it's exported out of a module (#118537)
If the std::initializer_list is exported out of module, its
`DeclContext` is not a namespace as `Sema::isStdInitializerList`
expects, but an `Decl::Kind::Export` and only its parent is a namespace.
So this commit makes `Sema::isStdInitializerList` account for that.

I'm really new to clang so I'm not 100% sure that was the issue, it
seems so and it fixes compilation. Also I probably need to add tests but
I'd like someone to approve the idea first.

Fixes https://github.com/llvm/llvm-project/issues/118218
2024-12-12 09:38:47 +08:00

40 lines
722 B
C++

// 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;
}