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

    <tr>
        <th>Summary</th>
        <td>
            Too aggresive C++23 static call operator optimization
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          shtanko-sv
      </td>
    </tr>
</table>

<pre>
    Hello,

It looks like clang is too aggressive for C++23 static call optimization. Here is the simplified example of real code:

```cpp
#include <functional>
#include <iostream>

template <typename Tag>
struct Wrapper {
    template <typename F, typename... Args>
    static void operator()(F&& callable, Args&&... args) {
        Invoke(std::forward<F>(callable), std::forward<Args>(args)...);
    }

    template <typename F, typename... Args>
    static void Invoke(F&& callable, Args&&... args) {
        std::invoke(std::forward<F>(callable), std::forward<Args>(args)...);
    }
};

struct Manager {
 template <typename SingletonClass>
    static SingletonClass& Get() {
 std::cout << "get call\n";
        static SingletonClass instance;
        return instance;
    }
};

struct Tag {};

int main()
{
    using TaggedWrapper = Wrapper<Tag>;
 Manager::Get<TaggedWrapper>()([] { std::cout << "Function\n"; });
}
```

We assume that Manager::Get() will be called and `get call` will be printed, but it doesn't happen. If change call in main to ` Manager::Get<TaggedWrapper>()([] { std::cout << "Function\n"; });` it works as expected. `get cal` also will be printed if remove `static` from `operator()`. It reproducible even with `-O0`. clang-17.0.1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VUGPozgT_TXmUmpETEPCgUN38uWbPqz2sC3NuQIFeNvYyC6Smf31K0OaJN1p7WFXE0Ug7OdXr57LLvRetYaoFNmzyHYRjtxZV_qO0bzZB3-MDrb-WX4jra2QW5HsRPI0P18YtLVvHrR6I6g0mhaUB7YWsG0dea-OBI11sBXyWchnmYJnZFVBhVqDHVj16i9kZU0M38jRtLwj8KoftGoU1UA_sB80gW3AEWqobE0ifbrWI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