Issue 127236
Summary Clang 19.1.0 - Extremely poor error message when dealing with callback functions and std::format
Labels
Assignees
Reporter 9291Sam
    Here's an MRE for this error.

[https://godbolt.org/z/b4sErhzqb](https://godbolt.org/z/b4sErhzqb)

```cpp
#include <iostream>
#include <vector>
#include <concepts>

struct CallBack
{
 void callback(std::invocable<int, std::size_t> auto func)
    {
        for (std::size_t i = 0; i < foo.size(); ++i)
        {
            func(foo[i], i);
        }
    }

    std::vector<int> foo;
};

void caller()
{
 CallBack c {};

    c.callback(
        [&](int i, std::size_t s)
 {
            // the error is below, there are 4 {} which correspond with only 3 arguments
            std::cout << std::format("{} {} {} {}", s, i, false);
        });
}
```

->
```cpp
<source>:11:13: error: call to immediate function 'caller()::(anonymous class)::operator()' is not a constant _expression_
   11 |             func(foo[i], i);
      | ^
<source>:22:7: note: in instantiation of function template specialization 'CallBack::callback<(lambda at <source>:23:9)>' requested here
   22 | c.callback(
      |       ^
<source>:11:18: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
   11 |             func(foo[i], i);
      | ^
1 error generated.
Compiler returned: 1
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to