llvm-project/clang/test/Modules/pr172241.cppm
Chuanqi Xu 6e1ab3a431
[Serialization] Stop demote var definition as declaration (#172430) (#177117) (#184287)
Close https://github.com/llvm/llvm-project/issues/172241 Close
https://github.com/llvm/llvm-project/issues/64034 Close
https://github.com/llvm/llvm-project/issues/149404 Close
https://github.com/llvm/llvm-project/issues/174858

After this patch, we (the clang dev) no longer assumes there are at most
one definition in a redeclaration chain.

See


https://discourse.llvm.org/t/rfc-clang-not-assuming-there-is-at-most-one-definition-in-a-redeclaration-chain/89360
for details.

---

Update since last commit:

Previously I remove the code to update visibility accidently. This is
the root cause of the failure.

---

Update since last commit:

Still demote var definition as declaration if it is in headers. This is
meant to avoid https://github.com/llvm/llvm-project/issues/181076

See the comments in ASTDeclReader::attachPreviousDeclImpl .

Close https://github.com/llvm/llvm-project/issues/181076
2026-03-04 10:06:58 +08:00

48 lines
1.0 KiB
C++

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/m.cppm -emit-module-interface -o %t/m.pcm
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/use.cpp -fmodule-file=m=%t/m.pcm -emit-llvm -o - | FileCheck %t/use.cpp
//
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/m.cppm -emit-reduced-module-interface -o %t/m.pcm
// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/use.cpp -fmodule-file=m=%t/m.pcm -emit-llvm -o - | FileCheck %t/use.cpp
//--- header.h
#pragma once
template <unsigned T>
class Templ {
public:
void lock() { __set_locked_bit(); }
private:
static constexpr auto __set_locked_bit = [](){};
};
class JT {
public:
~JT() {
Templ<4> state;
state.lock();
}
};
//--- m.cppm
module;
#include "header.h"
export module m;
export struct M {
JT jt;
};
//--- use.cpp
#include "header.h"
import m;
int main() {
M m;
return 0;
}
// CHECK: @_ZN5TemplILj4EE16__set_locked_bitE = {{.*}}linkonce_odr