<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80630>80630</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] nontrivial use of std::source_location::current() in a default argument fails
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pdimov
</td>
</tr>
</table>
<pre>
The following
```
#include <source_location>
#define BOOST_CURRENT_LOCATION_PTR \
[]( char const* fn ) \
{ \
static constexpr std::source_location loc = std::source_location::current(); \
return &loc; \
}( std::source_location::current().function_name() )
auto f( std::source_location const* loc = BOOST_CURRENT_LOCATION_PTR )
{
return loc;
}
auto g()
{
return f();
}
```
fails (for Clang trunk and Clang 17, with both libstdc++ and libc++) with
```
error: cannot take address of consteval function 'current' outside of an immediate invocation
```
(https://godbolt.org/z/jqqxq6njh)
GCC, MSVC accept.
The example is simplified to the point of doing not much at all, but it started out as something doing useful things. :-)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2P4jgQ_TXFpdTIcYCEQw5AD6uVdqdXPexekWM7xD2OTdtlpnd__coQunuYD2kQUmT7Vfm9V1UWMZqD07qB-Rrm9xORqPehOSoz-NOk9erfZtdr7Ly1_otxB2D3wFawYOP_suSlcdImpRHKTfQpSL23Xgoy3kH5YURdsUp3xmlcPzx82u03fz8-fvi42__xsFntfn_4uP9r94gw31zQiIgXZsBrlL0IKL2LBHyFnUPgyxtstX63EUmQkZcI_XIMGElBuYJydcMRrZcI5f0PAZdNmULQjoDXwJdQrr--O_-CphQyr4X18hsEVGcZv3DJtEtO5rO9E4O-7GXV7x0ViTx2P0v85tlV58-8f81erUfqo6qLpOvh_TccDqMxN9FvtnSvzt0m-bqfOmFsROB15wNurHAHpJDcZxROjeuiAr7BL4Z6bD31aE0bSUnga-DrM86adlxmzzLyu3fpEHyAcoVSOOcJSXzWKJQKOkb03dg8J2HxWgoEXr0WqUKfKBqlM1Y4NMOglRGk0bjTta7fn5m6JzrGXDC-Bb49eNV6S1MfDsC3_wHfPj0_vzwv3FN_U_DfNpss_s9P_2xQSKmPNH1_nOdVv4jhaDWaiNEMR2s6oxWSR-o1Hr1xlPkqb9wBs-ohyR4FobA2p24ToaE8P4G0yhJRRIx-0NTnkEtgirpLFs9bcYpQru6ALyeqKdWyXIqJboqKVQVblvVi0jfFXNTtrFoUop6pZVkVxWLBuZh3xbKWcyknpuGMzxhnczZnJVtMVVvMCiZZVbcz2XYMZkwPwtiptachGzUxMSbd1GxRsokVrbbx_JBxLnOXAOf5TQtNxt-16RBhxqyJFN8ykCF7fv3OfQXze3TeUTAnI2xWmH36hYFF41Cg0p1IllCEQxq0Izx39CQF29wU3VCf2qn0A_Bt5jR-7o7BP2lJwLdniRH49qzy_wAAAP__69K3Pg">