<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85335>85335</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Conflicting declaration error with `__using_if_exists__` in libc++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++,
embedded
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
petrhosek
</td>
</tr>
</table>
<pre>
When trying to use libc++ with LLVM libc on a baremetal platform, we encountered an issue with the `__using_if_exists__` attribute which was introduced in https://reviews.llvm.org/D90188:
```
In file included from /llvm_libcxx/include/algorithm:1973:
/llvm_libcxx/include/__algorithm/remove.h:28:1: error: declaration conflicts with target of using declaration already in scope
28 | remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
| ^
/llvm_libcxx/include/cstdio:155:1: note: target of using declaration
155 | using ::remove _LIBCPP_USING_IF_EXISTS;
| ^
/llvm_libcxx/include/cstdio:155:9: note: using declaration
155 | using ::remove _LIBCPP_USING_IF_EXISTS;
| ^
```
This is because baremetal version of the `stdio.h` libc header doesn't include `remove` (since there's no filesystem support).
A more minimal example of this issue is:
```cpp
void foo();
namespace N {
void bar();
using ::foo __attribute__((__using_if_exists__));
using ::bar __attribute__((__using_if_exists__));
}
void baz() {
N::bar();
}
```
This results in the following error (you can also see it at https://godbolt.org/z/dTxqnc1oP):
```
<source>:7:11: error: target of using declaration conflicts with declaration already in scope
7 | using ::bar __attribute__((__using_if_exists__));
| ^
<source>:7:3: note: target of using declaration
7 | using ::bar __attribute__((__using_if_exists__));
| ^
<source>:4:8: note: conflicting declaration
4 | void bar();
| ^
1 error generated.
Compiler returned: 1
```
Normally, `remove` is declared in `stdio.h`, which corresponds to the `foo` case.
In our case, there's no `remove` symbol in `stdio.h` and as such there's no such symbol in the global namespace, but there's `remove` in the `std::` namespace introduced by `algorithm` corresponding to the `bar` case.
Is this an issue with the `__using_if_exists__` implementation or intended behavior?
This is related to issue https://github.com/llvm/llvm-project/issues/84879.
CC @ldionne @zygoloid @AaronBallman @epilk
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV9uO4jgQ_RrzUlqUOISQBx6AHlZIs62RpvfyFjlxQbzj2FnbgWa-fuUkQNILvbdutbg4dtWpyzkumLXioBCXJF6T-GnCGldqs6zRmVJb_DbJNT8vfy1RgTNnoQ7gNDQWQYq8IHRN6BpOwpXw-fMvP7WLoBUwyJnBCh2TUEvm9tpUhG7ghICq0I1yaJADUyCsbbCz4EoEMg-yrLFCHTKxz_BVWGezjMwDYM4ZkTcO4VSKooQTsyCUM5o3BXIQCkrnakuiFaFbQrcGjwJPdirlsZpqcyB0-5QG4WLhdwRPJLi8zoP-v_26U7AXEkGoQjYcOeyNroDQrbeT-fheXwnd9o8J3TJ50Ea4siLRKkyTiEQr6C0_PpRlt2MeaqWPOC1JtKIeXuhtoDHa-A8cC8kMc0IrKLTaS1E422eMmQM60HtoUzbayqRBxs8-MbbQNfagAIAugCQb6LwSusi22pyY4TuHhjltIMv2wljnC3bnmWTdo0Ir6yB7qQmdQ5YdmWyQ0BRIsr75Amh9kfjT3yelsI4L7eOP40sWlHbo39-LtHcWxnHrq9vgqxytuhgh-7xbb758yX7-unv-Mdtts0-_7b6-fCXRxyBNh0gf4vsggJe_AdBxB3evL6WwICzkWDBP1xsfj2ish6X3F8a10UxLz7KWwCUyjga4RqsITdyFDH5v3zXzAAhdWKEK9FYMEppYULoljz1bhxXYpq61cYSm0yGyFVTaIFRCiYpJwFdW1RI7OC1mLwjCPqJpUdfdylELDnutCV0QmpJoPdyuWIW2ZgXCs2_ISxLbMzkzd8_AqDJ7rSHLrqqTZe2ZxT11ounQ2NhMzsx_M0OSpyG4Hvn3Dvkgpuern7dBXQ087A-DtpHO62jbCnstpT557K34-AqfdQMF82piNVhEEA6YeyO1B81zLV2vst8J3fKX1z9UEeovLaD39JZEG6sbUyCJPpFolXhSjfXvPeq_0cP39O_Go6T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