https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122646
Nathaniel Shead <nshead at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=122609,
| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=101140
--- Comment #4 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
(In reply to Alberto from comment #2)
> Thank you
>
> I have tested your reduced testcase on Compiler Explorer and doesn't
> reproduce there (perhaps r16-52a24bc had something to do).
>
Thanks! And yeah, should have tried again with the latest build, was a few
days behind... ah well. Confirmed that this commit fixed the issue, I've
pushed the reduced testcase for this as well.
> The example in comment #0 still fails with Compiler Explorer's version, but
> with a different error involving std::construct_at.
>
> This error also occurs with simply (https://godbolt.org/z/z9ojaen3x):
>
> ``` M.cpp
> export module M;
>
> import std;
>
> export
> template<typename>
> void foo(int n)
> {
> std::vector<int> u(n);
> }
> ```
>
> ``` main.cpp
> import M;
>
> int main()
> {
> foo<int>(10);
> }
> ```
>
> Perhaps I didn't set things up correctly. I don't usually use CMake.
Yeah so this seems similar to PR122609 for the name lookup or possibly
PR101140. Reduced:
// i.cpp
export module M;
export using size_t = decltype(sizeof(0));
export inline void* operator new(size_t, void* p) { return p; }
export template <typename T> void construct_at(T* p) { ::new(p) T; }
// j.cpp
export module X;
import M;
export template <typename T> void foo(T* p) { construct_at(p); }
// k.cpp
import X;
int main() {
int result;
foo(&result);
}
$ g++ -fmodules -S [ijk].cpp
In module M, imported at j.cpp:2,
of module X, imported at k.cpp:1:
i.cpp: In instantiation of ‘void construct_at@M(T*) [with T = int]’:
required from ‘void foo@X(T*) [with T = int]’
j.cpp:6:15:
6 | construct_at(p);
| ~~~~~~~~~~~~^~~
required from here
k.cpp:4:6:
4 | foo(&result);
| ~~~^~~~~~~~~
i.cpp:4:56: error: no matching function for call to ‘operator new(sizetype,
int*&)’
4 | export template <typename T> void construct_at(T* p) { ::new(p) T; }
| ^~~~~~~~~~
• there are 2 candidates
• candidate 1: ‘void* operator new(long unsigned int)’
• candidate expects 1 argument, 2 provided
• candidate 2: ‘void* operator new(long unsigned int, std::align_val_t)’
• no known conversion for argument 2 from ‘int*’ to ‘std::align_val_t’
Can workaround by doing `export import std;` in your original example, or by
`import std;` or `#include <new>` in every TU that needs to instantiate a
placement new.