<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59752>59752</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Sema::ForceDeclarationOfImplicitMembers generates deprecated members
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gmalecha
</td>
</tr>
</table>
<pre>
Using `Sema::ForceDeclarationOfImplicitMembers` can be problematic when used in combination with `-Werror -Wdeprecated-copy` because it can generate a deprecated member that is then flagged as an error. Here's a simple piece of code that triggers this:
```c++
struct C {
C(const C&) = default;
};
```
I'd like to extend the implementation to take an optional argument to not generate deprecated members. Essentially, this would look like:
```c++
void Sema::ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class, bool deprecated = true) {
if (!CanDeclareSpecialMemberFunction(Class))
return;
// If the default constructor has not yet been declared, do so now.
if (Class->needsImplicitDefaultConstructor())
DeclareImplicitDefaultConstructor(Class);
// If the copy constructor has not yet been declared, do so now.
if (Class->needsImplicitCopyConstructor() and
(deprecated or not Class->hasUserDeclaredCopyAssignment())) // <<< NEW
DeclareImplicitCopyConstructor(Class);
// If the copy assignment operator has not yet been declared, do so now.
if (Class->needsImplicitCopyAssignment() and
(deprecated or not Class->hasUserDeclaredCopyConstructor())) // <<< NEW
DeclareImplicitCopyAssignment(Class);
if (getLangOpts().CPlusPlus11) {
// If the move constructor has not yet been declared, do so now.
if (Class->needsImplicitMoveConstructor())
DeclareImplicitMoveConstructor(Class);
// If the move assignment operator has not yet been declared, do so now.
if (Class->needsImplicitMoveAssignment())
DeclareImplicitMoveAssignment(Class);
}
// If the destructor has not yet been declared, do so now.
if (Class->needsImplicitDestructor())
DeclareImplicitDestructor(Class);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vl1P4zgX_jXuzVGr1ClNe5ELJqV6kd7ZWe1oxNye2CeJF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