Chuanqi Xu 612e4e9d6d
[C++20] [Modules] Instantiate pending instantiations when GMF ends (#126842)
Close https://github.com/llvm/llvm-project/issues/125999

The cause of the problem is, when we instantiate the pending
instantiation, the owning module of the TU gets into 'foo' instead of
the GMF.

The concern of the patch is, I am not sure the point of 'pending'
instantiations. I mean, if there is a reason we **must** pending the
intantiations to the end of the TU.
2025-03-11 11:36:17 +08:00

34 lines
607 B
C++

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -verify -fsyntax-only
//--- bar.h
template <typename T>
struct Singleton {
static T* instance_;
static T* get() {
static bool init = false;
if (!init) {
init = true;
instance_ = ::new T();
}
return instance_;
}
};
template <typename T>
T* Singleton<T>::instance_ = nullptr;
struct s{};
inline void* foo() {
return Singleton<s>::get();
}
//--- foo.cppm
// expected-no-diagnostics
module;
#include "bar.h"
export module foo;