Skip to content

Document C2323 #4993

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

Merged
merged 4 commits into from
Mar 20, 2024
Merged
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
31 changes: 31 additions & 0 deletions docs/error-messages/compiler-errors-1/compiler-error-c2323.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "Compiler Error C2323"
description: "Learn more about: Compiler Error C2323"
ms.date: "03/20/2024"
f1_keywords: ["C2323"]
helpviewer_keywords: ["C2323"]
---
# Compiler Error C2323

'identifier': non-member operator `new` or `delete` functions may not be declared `static` or in a namespace other than the global namespace.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should keywords in error messages have backticks or be shown verbatim (raw with no backticks)? Since what I commonly see is the latter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to prevent machine translation. We weren't good about this and got complaints about crazy machine translations for things that shouldn't be translated in the first place. So, we started adding the back ticks.


The `new` and `delete` overload operators must be non-static, defined in the global namespace or as class members.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more precise it should be "operator overloads" and not "overload operators".

In addition, with the placement of the comma, one possible misinterpretation of the sentence is that new/delete operator overloads which are class members must be non-static. That is false as those can be declared static and even if the static keyword is not explicitly used, it is always a static member.

I will address these issues in a follow-up PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool. It was just a bit verbose before.

Copy link
Contributor Author

@Rageking8 Rageking8 Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can split it into 2 lines, one for the case where it is in the global namespace (emphasis on must be non-static), and the other is for class members (emphasis on optional static keyword and it being always static).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea


The following generates C2323:

```cpp
// C2323.cpp
// compile with: /c
static void* operator new(size_t); // C2323 since static
static void operator delete(void*); // C2323 since static

namespace NS
{
void* operator new(size_t); // C2323 since not defined in the global namespace
void operator delete(void*); // C2323 since not defined in the global namespace
}
```

## See also

[`new` and `delete` operators](../../cpp/new-and-delete-operators.md)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
description: "Learn more about: Compiler errors C2300 Through C2399"
title: "Compiler errors C2300 Through C2399"
ms.date: "04/21/2019"
f1_keywords: ["C2303", "C2304", "C2305", "C2306", "C2314", "C2321", "C2323", "C2328", "C2329", "C2330", "C2331", "C2335", "C2336", "C2339", "C2340", "C2342", "C2343", "C2347", "C2354", "C2358", "C2359", "C2363", "C2366", "C2367", "C2398", "C2399"]
helpviewer_keywords: ["C2303", "C2304", "C2305", "C2306", "C2314", "C2321", "C2323", "C2328", "C2329", "C2330", "C2331", "C2335", "C2336", "C2339", "C2340", "C2342", "C2343", "C2347", "C2354", "C2358", "C2359", "C2363", "C2366", "C2367", "C2398", "C2399"]
ms.assetid: 07ca45b5-b2f0-4049-837b-40a7a3caed88
f1_keywords: ["C2303", "C2304", "C2305", "C2306", "C2314", "C2321", "C2328", "C2329", "C2330", "C2331", "C2335", "C2336", "C2339", "C2340", "C2342", "C2343", "C2347", "C2354", "C2358", "C2359", "C2363", "C2366", "C2367", "C2398", "C2399"]
helpviewer_keywords: ["C2303", "C2304", "C2305", "C2306", "C2314", "C2321", "C2328", "C2329", "C2330", "C2331", "C2335", "C2336", "C2339", "C2340", "C2342", "C2343", "C2347", "C2354", "C2358", "C2359", "C2363", "C2366", "C2367", "C2398", "C2399"]
---
# Compiler errors C2300 Through C2399

Expand Down Expand Up @@ -39,7 +38,7 @@ The articles in this section of the documentation explain a subset of the error
|[Compiler error C2320](compiler-error-c2320.md)|expected ':' to follow access specifier '*specifier*'|
|Compiler error C2321|'*identifier*' is a keyword, and cannot be used in this context|
|[Compiler error C2322](compiler-error-c2322.md)|'*identifier*': address of dllimport '*identifier*' is not static|
|Compiler error C2323|'*identifier*': non-member operator new or delete functions may not be declared static or in a namespace other than the global namespace|
|[Compiler error C2323](compiler-error-c2323.md)|'*identifier*': non-member operator new or delete functions may not be declared static or in a namespace other than the global namespace|
|[Compiler error C2324](compiler-error-c2324.md)|'*identifier*': unexpected to the right of '::~'|
|[Compiler error C2325](compiler-error-c2325.md)|'*type1*': unexpected type to the right of '->~': expected '*type2*'|
|[Compiler error C2326](compiler-error-c2326.md)|'*declarator*': function cannot access '*identifier*'|
Expand Down
2 changes: 2 additions & 0 deletions docs/error-messages/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ items:
href: compiler-errors-1/compiler-error-c2320.md
- name: Compiler error C2322
href: compiler-errors-1/compiler-error-c2322.md
- name: Compiler error C2323
href: compiler-errors-1/compiler-error-c2323.md
- name: Compiler error C2324
href: compiler-errors-1/compiler-error-c2324.md
- name: Compiler error C2325
Expand Down