﻿# V1056\. The predefined identifier '\_\_func\_\_' always contains the string 'operator\(\)' inside function body of the overloaded 'operator\(\)'\.

The analyzer has detected the '\_\_func\_\_' identifier in the body of the overloaded '\(\)' operator\.

Consider the following example:

```cpp
class C
{
  void operator()(void)
  {
    std::cout << __func__ << std::endl;
  }
};

void foo()
{
  C c;
  c();
}
```

This code will output the string 'operator\(\)'\. This behavior may seem reasonable in code like this, so let's take a look at a less trivial example:

```cpp
void foo()
{
  auto lambda = [] () { return __func__; };
  std::cout << lambda() << std::endl;
}
```

It is important to remember that '\_\_func\_\_' is not a typical variable, so the following versions will not work as intended and the program will be still outputting the string 'operator\(\)':

```cpp
void fooRef()
{
  auto lambda = [&] () { return __func__; };
  std::cout << lambda() << std::endl;
}
void fooCopy()
{
  auto lambda = [=] () { return __func__; };
  std::cout << lambda() << std::endl;
}
```

In the case of lambdas, this can be fixed by passing '\_\_func\_\_' explicitly using a capture list:

```cpp
void foo()
{
  auto lambda = [func = __func__] () { return func; };
  std::cout << lambda() << std::endl;
}
```

To get full\-fledged output of the function name even inside the overloaded 'operator\(\)' or lambdas, you can use the platform/compiler\-specific macros\. The MSVC compiler provides three such macros:

* '\_\_FUNCTION\_\_' – outputs the function name including its namespace\. For example, this is what we will get for a lambda inside the main function: 'main::<lambda\_\.\.\.\.\>::operator \(\)';
* '\_\_FUNCSIG\_\_' – outputs the full function signature\. Similarly, it can be helpful when combined with a lambda: 'auto \_\_cdecl main::<lambda\_\.\.\.\.\>::operator \(\)\(void\) const';
* '\_\_FUNCDNAME\_\_' – outputs the decorated name of the function\. This information is quite specific, so it cannot fully replace '\_\_func\_\_'\.

Clang and GCC provide the following macros:

* '\_\_FUNCTION\_\_' – outputs the same name that the standard '\_\_func\_\_' does;
* '\_\_PRETTY\_FUNCTION\_\_' – outputs the full function signature\. For example, you will get the following output for a lambda: 'auto main\(\)::\(anonymous class\)::operator\(\)\(\) const'\.