<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/151371>151371</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Nested replacement field in format string fails to compile on Clang + libstdc++
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          namniav
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/89v5ahEcx
```c++
#include <print>

int main() {
    std::println("{:{}f}", 3.14f, 10);
}
```


GCC and libstdc++: OK


Clang and libc++: OK

Clang and libstdc++: Error

> ```c++
> <source>:4:18: error: call to consteval function 'std::basic_format_string<char, float, int>::basic_format_string<char[7]>' is not a constant expression
>     4 | std::println("{:{}f}", 3.14f, 10);
>       |                  ^
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:339:4: note: undefined function '__check_dynamic_spec<int, unsigned int, long long, unsigned long long>' cannot be used in a constant expression
>   339 | __check_dynamic_spec<int, unsigned, long long,
>       |           ^
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:681:6: note: in call to '__pc.check_dynamic_spec_integral(1)'
>   681 | __pc.check_dynamic_spec_integral(__val);
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:697:16: note: in call to '_S_parse_width_or_precision(&"{:{}f}"[3], &"{:{}f}"[6], __spec._M_width, __arg_id, __scanner._Scanner::_M_pc)'
>   697 | auto __next = _S_parse_width_or_precision(__first, __last, _M_width,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   698 | __arg_id, __pc);
>       | ~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:2001:16: note: in call to '__spec._M_parse_width(&"{:{}f}"[2], &"{:{}f}"[6], __scanner._Scanner::_M_pc)'
>  2001 |             __first = __spec._M_parse_width(__first, __last, __pc);
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:2866:16: note: in call to 'this->_M_f.parse(__scanner._Scanner::_M_pc)'
>  2866 | { return _M_f.parse(__pc); }
>       |                ^~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:5015:31: note: in call to '__f.parse(__scanner._Scanner::_M_pc)'
>  5015 | this->_M_pc.advance_to(__f.parse(this->_M_pc));
>       | ^~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:5001:3: note: in call to 'this->_M_parse_format_spec<float, int>(0)'
>  5001 | _M_parse_format_spec<_Args...>(__id);
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:4909:2: note: in call to 'this->_M_format_arg(0)'
>  4909 | _M_format_arg(__id);
>       |         ^~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:4857:7: note: in call to 'this->_M_on_replacement_field()'
>  4857 | _M_on_replacement_field();
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:5163:2: note: in call to '__scanner._M_scan()'
>  5163 | __scanner._M_scan();
>       |         ^~~~~~~~~~~~~~~~~~~
> <source>:4:18: note: in call to 'basic_format_string<char[7]>("{:{}f}")'
>     4 | std::println("{:{}f}", 3.14f, 10);
>       |                  ^~~~~~~~
> /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/format:390:2: note: declared here
>   390 |         __check_dynamic_spec(size_t __id) noexcept;
>       |         ^
> 1 error generated.
> ```


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWMuS6yYTfhq8oUYlgXVbeKHx5V_8NcniPACFEJZJMKgAOT5nkWdPIeQZ2-PbnKRSjsolaUTTNN_30dNArRWt4nwG0leQLia0dxttZopulaC7Sa2b77ONc50FuAJoBdCq1U2tpYu0aQFa_QBoVZS7lG6WbA_iCmRx-DGAXv0vrgDCQjHZNxwCPO-MUA7gpW-IK6Ec3FKhACoAKiHIfQcIIbSu8SPiarCXwQD5dlz5e75Yg3zhP6E5xFEyXfuXJAaoBHgYNV8chxOGA3H1v_kcUtVAKWrrmkOUuIK__v_dZi6pag9WF0xO2k-9LI3RZnSEl_ASHP4znlvdG8Y9ELiaAlwlhe_Oh-64goxKCZ2GTCvr-I5KuO4Vc0IrCFD-jk5NrWBkrc2WOmKdEaoFeM421Hg41lJT519GyO91SV9zkC68JcqhsFBpB2kIgSoH-b4z3Fqh1TgNf00hyOf_AF2jOzi4-3SBdHmADq105wBaMb3thOTmhe87qQ03XpuMvVhFO7vR3kSKOnwEaLUvMpJNX6RQ_f6lVT1AqySL4igGaBVFn2-jZP1AI3VHHQJ6AFcYlyN_Hizun71q-Foo3pwwRgjbcPY7ab4ruhWM2I4zgOeeGDSHvRpWYQPHv6VW7XA7afz4GhhiVHmGag57O_S9QxbG5YDuY7Gcx3GDpGdlJysSfz9mR6j3pTWw0rHoMxhEKMdbQyVAReIlivL32WdFMoJ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