Skip to content

Commit

Permalink
Update Where we Apply Deprecated Attributes in C++ (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Jun 19, 2024
1 parent 65f3190 commit b81c856
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
7 changes: 5 additions & 2 deletions cpp/include/IceUtil/PushDisableWarnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
# pragma warning(disable : 4251) // class ... needs to have dll-interface to be used by clients of class ...
# pragma warning(disable : 4512) // ... assignment operator could not be generated
# pragma warning(disable : 4275) // non dll-interface class ... used as base for dll-interface class ...
# pragma warning(disable : 4996) // ... was declared deprecated

#elif defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wredundant-decls" // expected when using forward Slice declarations
# pragma clang diagnostic ignored "-Wdocumentation-deprecated-sync" // see zeroc-ice/ice issue #211
# pragma clang diagnostic ignored "-Wdeprecated-declarations" // allow referencing deprecated Slice definitions

# if (__clang_major__ >= 4)
# pragma clang diagnostic ignored "-Wshadow-field-in-constructor" // expected in some generated header files
Expand All @@ -29,6 +31,7 @@

#elif defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wredundant-decls" // expected when using forward Slice declarations
# pragma GCC diagnostic ignored "-Wshadow" // expected in some generated header files
# pragma GCC diagnostic ignored "-Wredundant-decls" // expected when using forward Slice declarations
# pragma GCC diagnostic ignored "-Wshadow" // expected in some generated header files
# pragma GCC diagnostic ignored "-Wdeprecated-declarations" // allow referencing deprecated Slice definitions
#endif
56 changes: 36 additions & 20 deletions cpp/src/slice2cpp/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ namespace
}
}

string getDeprecateSymbol(const ContainedPtr& p1)
string getDeprecatedSymbol(const ContainedPtr& p1)
{
string deprecatedSymbol;
if (p1->isDeprecated(true))
if (p1->isDeprecated(false)) // 'false' means: don't check the parent type.
{
if (auto reason = p1->getDeprecationReason(true))
if (auto reason = p1->getDeprecationReason(false))
{
deprecatedSymbol = "[[deprecated(\"" + *reason + "\")]] ";
}
Expand Down Expand Up @@ -805,16 +805,19 @@ Slice::Gen::generate(const UnitPtr& p)
}

//
// Disable shadow warnings in .cpp file
// Disable shadow and deprecation warnings in .cpp file
//
C << sp;
C.zeroIndent();
C << nl << "#if defined(_MSC_VER)";
C << nl << "# pragma warning(disable:4458) // declaration of ... hides class member";
C << nl << "# pragma warning(disable : 4458) // declaration of ... hides class member";
C << nl << "# pragma warning(disable : 4996) // ... was declared deprecated";
C << nl << "#elif defined(__clang__)";
C << nl << "# pragma clang diagnostic ignored \"-Wshadow\"";
C << nl << "# pragma clang diagnostic ignored \"-Wdeprecated-declarations\"";
C << nl << "#elif defined(__GNUC__)";
C << nl << "# pragma GCC diagnostic ignored \"-Wshadow\"";
C << nl << "# pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"";
C << nl << "#endif";

printVersionCheck(H);
Expand Down Expand Up @@ -1251,7 +1254,8 @@ Slice::Gen::ForwardDeclVisitor::visitClassDecl(const ClassDeclPtr& p)
string name = fixKwd(p->name());

H << nl << "class " << name << ';';
H << nl << "using " << p->name() << "Ptr = ::std::shared_ptr<" << name << ">;" << sp;
H << nl << "using " << p->name() << "Ptr " << getDeprecatedSymbol(p) << "= ::std::shared_ptr<" << name << ">;"
<< sp;
}

bool
Expand All @@ -1277,7 +1281,7 @@ Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p)
{
H << "class ";
}
H << fixKwd(p->name());
H << getDeprecatedSymbol(p) << fixKwd(p->name());
if (!unscoped && p->maxValue() <= 0xFF)
{
H << " : ::std::uint8_t";
Expand All @@ -1293,6 +1297,16 @@ Slice::Gen::ForwardDeclVisitor::visitEnum(const EnumPtr& p)
{
writeDocSummary(H, *en);
H << nl << fixKwd((*en)->name());

string deprecatedSymbol = getDeprecatedSymbol(*en);
if (!deprecatedSymbol.empty())
{
// The string returned by `deprecatedSymbol` has a trailing space character,
// here we need to remove it, and instead add it to the front.
deprecatedSymbol.pop_back();
H << ' ' << deprecatedSymbol;
}

//
// If any of the enumerators were assigned an explicit value, we emit
// an explicit value for *all* enumerators.
Expand Down Expand Up @@ -1377,7 +1391,8 @@ Slice::Gen::ForwardDeclVisitor::visitConst(const ConstPtr& p)
const string scope = fixKwd(p->scope());
writeDocSummary(H, p);
H << nl << (isConstexprType(p->type()) ? "constexpr " : "const ")
<< typeToString(p->type(), false, scope, p->typeMetaData(), _useWstring) << " " << fixKwd(p->name()) << " = ";
<< typeToString(p->type(), false, scope, p->typeMetaData(), _useWstring) << " " << fixKwd(p->name()) << " "
<< getDeprecatedSymbol(p) << "= ";
writeConstantValue(H, p->type(), p->valueType(), p->value(), _useWstring, p->typeMetaData(), scope);
H << ';' << sp;
}
Expand Down Expand Up @@ -1482,8 +1497,8 @@ Slice::Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)

H << sp;
writeDocSummary(H, p);
H << nl << "class " << _dllExport << p->name() << "Prx : public " << getUnqualified("::Ice::Proxy", scope) << "<"
<< fixKwd(p->name() + "Prx") << ", ";
H << nl << "class " << _dllExport << getDeprecatedSymbol(p) << p->name() << "Prx : public "
<< getUnqualified("::Ice::Proxy", scope) << "<" << fixKwd(p->name() + "Prx") << ", ";
if (bases.empty())
{
H << getUnqualified("::Ice::ObjectPrx", scope);
Expand Down Expand Up @@ -1675,7 +1690,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
string futureTAbsolute = createOutgoingAsyncTypeParam(createOutgoingAsyncParams(p, "", _useWstring));
string lambdaT = createOutgoingAsyncTypeParam(lambdaOutParams);

const string deprecateSymbol = getDeprecateSymbol(p);
const string deprecatedSymbol = getDeprecatedSymbol(p);

CommentPtr comment = p->parseComment(false);
const string contextDoc = "@param " + contextParam + " The Context map to send with the invocation.";
Expand All @@ -1691,7 +1706,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
postParams.push_back(contextDoc);
writeOpDocSummary(H, p, comment, OpDocAllParams, true, StringList(), postParams, comment->returns());
}
H << nl << deprecateSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << contextDecl << epar << " const;";
H << nl << deprecatedSymbol << retS << ' ' << fixKwd(name) << spar << paramsDecl << contextDecl << epar
<< " const;";

C << sp;
C << nl << retSImpl << nl << scoped << fixKwd(name) << spar << paramsImplDecl << "const ::Ice::Context& context"
Expand Down Expand Up @@ -1748,7 +1764,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
writeOpDocSummary(H, p, comment, OpDocInParams, false, StringList(), postParams, returns);
}

H << nl << deprecateSymbol << "::std::future<" << futureT << "> " << name << "Async" << spar << inParamsDecl
H << nl << deprecatedSymbol << "::std::future<" << futureT << "> " << name << "Async" << spar << inParamsDecl
<< contextDecl << epar << " const;";

C << sp;
Expand Down Expand Up @@ -1784,7 +1800,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
writeOpDocSummary(H, p, comment, OpDocInParams, false, StringList(), postParams, returns);
}
H << nl;
H << deprecateSymbol;
H << deprecatedSymbol;
H << "::std::function<void()>";

// TODO: need "nl" version of spar/epar
Expand Down Expand Up @@ -2018,7 +2034,7 @@ Slice::Gen::DataDefVisitor::visitStructStart(const StructPtr& p)

H << sp;
writeDocSummary(H, p);
H << nl << "struct " << fixKwd(p->name());
H << nl << "struct " << getDeprecatedSymbol(p) << fixKwd(p->name());
H << sb;

return true;
Expand Down Expand Up @@ -2094,7 +2110,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p)

H << sp;
writeDocSummary(H, p);
H << nl << "class " << _dllClassExport << name << " : public " << baseClass;
H << nl << "class " << _dllClassExport << getDeprecatedSymbol(p) << name << " : public " << baseClass;
H << sb;

H.dec();
Expand Down Expand Up @@ -2317,7 +2333,7 @@ Slice::Gen::DataDefVisitor::visitClassDefStart(const ClassDefPtr& p)

H << sp;
writeDocSummary(H, p);
H << nl << "class " << _dllClassExport << name << " : public ";
H << nl << "class " << _dllClassExport << getDeprecatedSymbol(p) << name << " : public ";

if (!base)
{
Expand Down Expand Up @@ -2637,7 +2653,8 @@ Slice::Gen::DataDefVisitor::emitDataMember(const DataMemberPtr& p)
string scope = "";

writeDocSummary(H, p);
H << nl << typeToString(p->type(), p->optional(), scope, p->getMetaData(), _useWstring) << ' ' << name;
H << nl << getDeprecatedSymbol(p) << typeToString(p->type(), p->optional(), scope, p->getMetaData(), _useWstring)
<< ' ' << name;

string defaultValue = p->defaultValue();
if (!defaultValue.empty())
Expand Down Expand Up @@ -3070,7 +3087,6 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p)
string isConst = p->hasMetaData("cpp:const") ? " const" : "";

string opName = amd ? (name + "Async") : fixKwd(name);
string deprecateSymbol = getDeprecateSymbol(p);

H << sp;
if (comment)
Expand All @@ -3093,7 +3109,7 @@ Slice::Gen::InterfaceVisitor::visitOperation(const OperationPtr& p)
postParams.push_back("@param " + currentParam + " The Current object for the invocation.");
writeOpDocSummary(H, p, comment, pt, true, StringList(), postParams, returns);
}
H << nl << deprecateSymbol << "virtual " << retS << ' ' << opName << spar << params << epar << isConst << " = 0;";
H << nl << "virtual " << retS << ' ' << opName << spar << params << epar << isConst << " = 0;";
H << nl << "/// \\cond INTERNAL";
H << nl << "void _iceD_" << name << "(::Ice::IncomingRequest&, ::std::function<void(::Ice::OutgoingResponse)>)"
<< isConst << ';';
Expand Down

0 comments on commit b81c856

Please sign in to comment.