Skip to content

Add example and tweak C3187 error reference #5665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions docs/error-messages/compiler-errors-2/compiler-error-c3187.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
---
description: "Learn more about: Compiler Error C3187"
title: "Compiler Error C3187"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C3187"
ms.date: 08/15/2025
f1_keywords: ["C3187"]
helpviewer_keywords: ["C3187"]
ms.assetid: 9d2ebf55-1a6a-4087-bf5b-5274baae6351
---
# Compiler Error C3187

> '`__func__`' : is only available within the body of a function
> '`__func__`': is only available within the body of a function

## Remarks

The predefined identifier [`__func__`](../../cpp/func.md) is not available outside the body of a function.

To correct this error, move the identifier inside the body of a function.

## Example

The following example generates C3187:

```cpp
// C3187.cpp
// compile with: /c

auto global = __func__; // C3187, usage in global scope

void func(const char* f = __func__); // C3187, usage in parameter list
```

The predefined macro is not available outside the body of a function.
## See also

To correct this error, move the macro inside the body of a function.
[C2457](../compiler-errors-1/compiler-error-c2457.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about: Compiler errors C3100 Through C3199"
title: "Compiler errors C3100 Through C3199"
description: "Learn more about: Compiler errors C3100 Through C3199"
ms.date: 06/01/2022
f1_keywords: ["C3102", "C3105", "C3107", "C3108", "C3109", "C3111", "C3112", "C3119", "C3122", "C3123", "C3124", "C3125", "C3127", "C3128", "C3129", "C3143", "C3144", "C3146", "C3147", "C3148", "C3151", "C3158", "C3164", "C3165", "C3169", "C3177", "C3178", "C3184", "C3186", "C3188", "C3191", "C3193"]
helpviewer_keywords: ["C3102", "C3105", "C3107", "C3108", "C3109", "C3111", "C3112", "C3119", "C3122", "C3123", "C3124", "C3125", "C3127", "C3128", "C3129", "C3143", "C3144", "C3146", "C3147", "C3148", "C3151", "C3158", "C3164", "C3165", "C3169", "C3177", "C3178", "C3184", "C3186", "C3188", "C3191", "C3193"]
Expand Down Expand Up @@ -102,7 +102,7 @@ The articles in this section of the documentation explain a subset of the error
| Compiler error C3184 | Obsolete. |
| [Compiler error C3185](compiler-error-c3185.md) | 'typeid': used on managed/WinRT type '*type*', use '*operator*' instead |
| Compiler error C3186 | Obsolete. |
| [Compiler error C3187](compiler-error-c3187.md) | '*identifier*': is only available within the body of a function |
| [Compiler error C3187](compiler-error-c3187.md) | '`__func__`': is only available within the body of a function |
| Compiler error C3188 | Obsolete. |
| [Compiler error C3189](compiler-error-c3189.md) | 'typeid<*declarator*>': this syntax is no longer supported, use::typeid instead (Obsolete in Visual Studio 2022.) |
| [Compiler error C3190](compiler-error-c3190.md) | '*declarator*' with the provided template arguments is not the explicit instantiation of any member function of '*type*' |
Expand Down