| Issue |
184957
|
| Summary |
Spurious 'operator new' ambiguous error with modules and libc++
|
| Labels |
libc++
|
| Assignees |
|
| Reporter |
kamrann
|
This has shown up at some point since clang 21 or 22 for me and prevented me from staying on latest clang. I'll try to reduce the standard library includes at some point but it's already been very time-consuming to get to this point. For now this is what I have:
```
// wrap.std.tt.mxx
module;
#include <type_traits>
export module wrap.std.tt;
```
```
// wrap.std.tt2.mxx
module;
#include <type_traits>
export module wrap.std.tt2;
```
```
// wrap.std.vec.mxx
module;
#include <vector>
export module wrap.std.vec;
```
```
// wrap.std.vec.reexport.mxx
export module wrap.std.vec.reexport;
export import wrap.std.vec;
```
```
// repro_dep.mxx
module;
#include <vector>
export module repro_dep;
import wrap.std.tt;
import wrap.std.vec.reexport;
import wrap.std.tt2;
import std;
export using StringViewType = std::basic_string_view<char>;
```
```
// repro.cxx
import std;
import repro_dep;
auto f() -> void
{
std::deque< std::string > strings;
strings.emplace_back();
}
```
```
clang version 23.0.0git (https://github.com/llvm/llvm-project.git b86f24fd0ed47238ddfa1292bbd89d1ec10d774c)
Target: x86_64-unknown-linux-gnu
```
```
In module 'std' imported from /home/cjangus/repros/clang/ambiguous-new/ambiguous-new/repro.cxx:1:
/home/cjangus/opt/clang-trunk/bin/../include/c++/v1/__new/allocate.h:39:30: error: call to 'operator new' is ambiguous
39 | return static_cast<_Tp*>(__builtin_operator_new(__size, static_cast<align_val_t>(__align)));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/cjangus/opt/clang-trunk/bin/../include/c++/v1/__memory/allocator.h:92:19: note: in instantiation of function template specialization 'std::__libcpp_allocate<std::__1::basic_string<char> *>' requested here
92 | return std::__libcpp_allocate<_Tp>(__element_count(__n));
| ^
/home/cjangus/opt/clang-trunk/bin/../include/c++/v1/deque:1627:5: note: in instantiation of member function 'std::__1::deque<std::__1::basic_string<char>>::__add_back_capacity' requested here
1627 | __add_back_capacity();
| ^
/home/cjangus/repros/clang/ambiguous-new/ambiguous-new/repro.cxx:8:11: note: in instantiation of function template specialization 'std::__1::deque<std::__1::basic_string<char>>::emplace_back<>' requested here
7 | strings.emplace_back();
| ^
/home/cjangus/opt/clang-trunk/bin/../include/c++/v1/__new/global_new_delete.h:49:54: note: candidate function
49 | [[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
| ^
note: candidate function
```
Aside from starting to rip apart the standard headers, removing any part of the above results in the error going away.
Some things that seem curious.
- I'm using `-fmodules-reduced-bmi` (maybe that's default now anyway?), so it seems surprising that a module that just includes a header and has an empty purview would cause any such downstream effects.
- Even though `wrap.std.vec.reexport` does nothing other than re-export `wrap.std.vec`, replacing `import wrap.std.vec.reexport;` with `import wrap.std.vec;` results in the error going away.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs