From 80dec2ecfffe30f86ecfeec8f553b16bb992c48b Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Thu, 14 Jul 2022 14:54:48 -0700 Subject: [PATCH] [Clang] Modify CXXMethodDecl::isMoveAssignmentOperator() to look through type sugar AcceptedPublic Currently CXXMethodDecl::isMoveAssignmentOperator() does not look though type sugar and so if the parameter is a type alias it will not be able to detect that the method is a move assignment operator. This PR fixes that and adds a set of tests that covers that we correctly detect special member functions when defaulting or deleting them. This fixes: https://github.com/llvm/llvm-project/issues/56456 Differential Revision: https://reviews.llvm.org/D129591 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/AST/DeclCXX.cpp | 2 +- .../SemaCXX/cxx0x-defaulted-functions.cpp | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a02bc0a2f691..17c1dac2e82a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -186,6 +186,8 @@ Bug Fixes - Clang now checks ODR violations when merging concepts from different modules. Note that this may possibly break existing code, and is done so intentionally. Fixes `Issue 56310 `_. +- Clang will now look through type sugar when checking a member function is a + move assignment operator. Fixes `Issue 56456 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 6fc9a86bc3cf..c307cbe02ecf 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -2410,7 +2410,7 @@ bool CXXMethodDecl::isMoveAssignmentOperator() const { return false; QualType ParamType = getParamDecl(0)->getType(); - if (!isa(ParamType)) + if (!ParamType->isRValueReferenceType()) return false; ParamType = ParamType->getPointeeType(); diff --git a/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp b/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp index 25a40ef49401..73916fd3027e 100644 --- a/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp +++ b/clang/test/SemaCXX/cxx0x-defaulted-functions.cpp @@ -259,3 +259,28 @@ namespace P1286R2 { static_assert(noexcept(A::B()), ""); } + +namespace GH56456 { +template +using RC=T const&; +template +using RV=T&; +template +using RM=T&&; + +struct A { + A(RC) = default; + A(RM) = default; + + auto operator=(RC) -> RV = default; + auto operator=(RM) -> RV = default; +}; + +struct B { + B (RC) = delete; + B (RM) = delete; + + auto operator = (RC) -> RV = delete; + auto operator = (RM) -> RV = delete; +}; +}