diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3056,12 +3056,13 @@ // variable will no longer be used. if (VD->hasAttr()) return false; + // ...non-volatile... + if (VD->getType().isVolatileQualified()) + return false; + if (CESK & CES_AllowDifferentTypes) return true; - // ...non-volatile... - if (VD->getType().isVolatileQualified()) return false; - // Variables with higher required alignment than their type's ABI // alignment cannot use NRVO. if (!VD->getType()->isDependentType() && VD->hasAttr() && diff --git a/clang/test/SemaCXX/implicitly-movable.cpp b/clang/test/SemaCXX/implicitly-movable.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/implicitly-movable.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify %s +// expected-no-diagnostics + +class A { +public: + A() {} + ~A() {} + A(A &&); + A(const volatile A &); + +private: + A(const A &); + A(volatile A &&); +}; + +A test_volatile() { + volatile A a_copy; + return a_copy; +} + +A test_normal() { + A a_move; + return a_move; +} \ No newline at end of file