<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101580>101580</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
detect non-working `std::as_const()` usage with pointers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
c++17,
check-request
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
#include <cassert>
#include <utility>
int main()
{
struct C {
bool written = false;
void f() {
written = true;
}
void f() const {}
};
{
C c;
c.f();
assert(c.written);
}
{
C c;
std::as_const(c).f();
assert(!c.written);
}
{
C c;
C* cp = &c;
cp->f();
assert(c.written);
}
{
C c;
C* cp = &c;
std::as_const(cp)->f();
assert(!c.written);
}
}
```
```
output.s: /app/example.cpp:34: int main(): Assertion `!c.written' failed.
```
https://godbolt.org/z/e9scdsTe1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVNGSojoQ_ZrmJSUVOijwwAPq8AX3_VYILWYnEpYE3dmv3wqjq6PWzG7VpigI3eGc04d0pHO664lKWK5huY3k5Pd2LHd6pJM8UtTY9q2EFX-_1DAA3wKvAIXulZlaYiA2SjpHowfx8iw7eW20f7tm57vuPTtI3QPmgMU5k63fJ4wx5vw4Kc827BptrDXsNGrvqWcgtmwnjSMQN1-FcbS6Zbt3YPYB8zJuMfw4PUJAtv0EU9ne-Rn5dll4ueDcRi_QG6YeeFR8xnzInC3FXMVntferruQPNT6jcr4FUYGopPt_LiBgAxaPCn5TAyZ_wP6hyE8EbAArpobZdMDVEzOGBYiXf2HIl75_qeWpWwNg8VTi3zl2nVz66nbT3AXt5IfJxw5ExQBrOQyANf2Qh8FQHPpRVCINybuGEhWrZlXa9iygfVCWsZ3Uhtr4EyF774dAC1gD1p1tG2t8bMcOsP4ZRBROte4_SqK2FG0hChlRmWSIy2Wap0W0L3PerPiOSCRylTdJtsql4G2eiRR3vMiLSJfIMeU5T1BghkUs04wypKxVpGQuV5ByOkhtYmOOh8AdaecmKhOeLHMeGdmQcfPZhaiM7LuF1-0bIAJuQghwDbhOsmtkT-p1MdL3icI_xXDmjWVAXzRT5yDlRjvvrnxee0NlS56UZ73tFyc7vuq-C54-2yTB-xVnk5MdsZP2ezZY3XsaXTSNprwzVfv91MTKHgDrQHl-LIbRfiPlAeu5XgdYn0s-lvgrAAD__8BigPc">