Skip to content

Commit

Permalink
Added support for P2573: = delete("reason");.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasfertig committed Jan 12, 2025
1 parent 5a8071a commit ea9fc03
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
19 changes: 12 additions & 7 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3184,13 +3184,6 @@ void CodeGenerator::InsertCXXMethodHeader(const CXXMethodDecl* stmt, OutputForma

InsertTemplateGuardBegin(stmt);
InsertFunctionNameWithReturnType(*stmt, cxxInheritedCtorDecl);

if(stmt->isDeleted()) {
mOutputFormatHelper.AppendNewLine(kwSpaceEqualsDelete);

} else if(stmt->isDefaulted()) {
mOutputFormatHelper.AppendNewLine(kwSpaceEqualsDefault);
}
}
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -4993,6 +4986,18 @@ void CodeGenerator::InsertFunctionNameWithReturnType(const FunctionDecl& d
#endif
mOutputFormatHelper.Append(" = 0"sv);
}

if(decl.isDeleted()) {
mOutputFormatHelper.Append(kwSpaceEqualsDelete);
if(auto* delInfo = decl.getDefalutedOrDeletedInfo()) {
WrapInParens([&]() { InsertArg(delInfo->getDeletedMessage()); }, AddSpaceAtTheEnd::No);
} else {
mOutputFormatHelper.AppendSemiNewLine();
}

} else if(decl.isDefaulted()) {
mOutputFormatHelper.AppendNewLine(kwSpaceEqualsDefault);
}
}
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion InsightsStaticStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using namespace std::literals;
#define KW_CO_AWAIT "co_await"
#define KW_TYPENAME "typename"
#define KW_EQUALS_DEFAULT "= default;"
#define KW_EQUALS_DELETE "= delete;"
#define KW_EQUALS_DELETE "= delete"
#define KW_INTERNAL_THIS "__this"
#define KW_ELIPSIS "..."
#define KW_FALSE "false"
Expand Down
4 changes: 4 additions & 0 deletions tests/p2573Test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// cmdline:-std=c++26

void newapi();
void oldapi() = delete("This old API is outdated and already been removed. Please use newapi() instead.");
2 changes: 2 additions & 0 deletions tests/p2573Test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void newapi();
inline void oldapi() = delete("This old API is outdated and already been removed. Please use newapi() instead.");

0 comments on commit ea9fc03

Please sign in to comment.