[libcxx] Ambiguous Reference to std::pair in SPEC2006 447.dealII Example When Using libc++
When compiling the code from the SPEC2006 447.dealII benchmark with libc++, an ambiguous reference to std::pair occurs. The problematic code like this:
#include <utility>
namespace std {
template <typename T1, typename T2> struct pair;
} // namespace std
std::pair<unsigned, unsigned> test() { return std::make_pair(1u, 2u); }
The error message is:
test.cpp:6:6: error: reference to 'pair' is ambiguous
6 | std::pair<unsigned, unsigned> test() { return std::make_pair(1u, 2u); }
| ^
../riscv64-unknown-elf/include/c++/v1/__utility/pair.h:79:29: note: candidate found by name lookup is 'std::__1::pair'
79 | struct _LIBCPP_TEMPLATE_VIS pair
| ^
test.cpp:3:44: note: candidate found by name lookup is 'std::pair'
3 | template <typename T1, typename T2> struct pair;
| ^
1 error generated.
Is there a recommended approach to resolve this issue without modifying the SPEC2006 source code? Could libc++ provide a mechanism to handle such forward declarations gracefully?
This program violates [namespace.std], so it has undefined behavior (or is ill-formed, no diagnostic required per P3534R0).
I don't think libc++ can accept this example. It's possible to directly provide pair in std but not in any nested inline namespace, but this will break ABI with nearly zero value.
The recommended approach is to fix SPEC2006. As @frederick-vs-ja pointed our this code violates the "Constraints on programs". It would be interesting why they think this is needed.