Issue |
151371
|
Summary |
Nested replacement field in format string fails to compile on Clang + libstdc++
|
Labels |
clang
|
Assignees |
|
Reporter |
namniav
|
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.
> ```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs