[clang] [Clang] diagnose deleted/default redeclaration of defined friend functions (PR #136717)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 05:22:49 PDT 2025
================
@@ -142,6 +142,14 @@ NamedDecl *Parser::ParseCXXInlineMethodDef(
SkipUntil(tok::semi);
}
+ if (FunctionDecl *FD =
+ dyn_cast_if_present<FunctionDecl>(FnD->getPreviousDecl())) {
+ if (isa<CXXRecordDecl>(FD->getLexicalDeclContext()) ||
+ Actions.getDefaultedFunctionKind(FD).asComparison() ==
+ Sema::DefaultedComparisonKind::None)
----------------
a-tarasyuk wrote:
@zyn0217, thanks for the feedback.
> 1. we have to check the semantics on the parser side
The `ParseCXXInlineMethodDef` method handles function redefinitions
https://github.com/llvm/llvm-project/blob/dde00f5e22e81ac88b37d1502d2383985a58329d/clang/lib/Parse/ParseCXXInlineMethods.cpp#L70
https://github.com/llvm/llvm-project/blob/dde00f5e22e81ac88b37d1502d2383985a58329d/clang/lib/Parse/ParseCXXInlineMethods.cpp#L170-L174
however, it appears to skip over `= default` and `= delete` cases without any specific handling
https://github.com/llvm/llvm-project/blob/dde00f5e22e81ac88b37d1502d2383985a58329d/clang/lib/Parse/ParseCXXInlineMethods.cpp#L145
I believe these cases can also be addressed at this stage. Alternatively, consider extending
https://github.com/llvm/llvm-project/blob/e35cc2d387e170d0e1f6ef647f17423262feb1ea/clang/lib/Sema/SemaDeclCXX.cpp#L7711
and adding a similar check for `deleted` functions... not sure about this alternative
> we have to special-case the comparison operators
for cases involving _comparison operators_, for `delete` and `default`, there are more specific diagnostics
https://github.com/llvm/llvm-project/blob/e35cc2d387e170d0e1f6ef647f17423262feb1ea/clang/lib/Sema/SemaDeclCXX.cpp#L9096-L9140
if cases like _comparisons_ or _declarations outside of scope_ are not skipped, these diagnostics will be replaced with a general redefinition diagnostic message
https://github.com/llvm/llvm-project/blob/e35cc2d387e170d0e1f6ef647f17423262feb1ea/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp#L195-L199
https://github.com/llvm/llvm-project/pull/136717
More information about the cfe-commits
mailing list