[PATCH] D88295: [Sema] Fix volatile check when test if a return object can be implicitly move

Yang Fan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 26 01:06:28 PDT 2020


nullptr.cpp updated this revision to Diff 294485.
nullptr.cpp added a comment.

Add test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88295/new/

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/implicitly-movable.cpp


Index: clang/test/SemaCXX/implicitly-movable.cpp
===================================================================
--- /dev/null
+++ 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
Index: clang/lib/Sema/SemaStmt.cpp
===================================================================
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3056,12 +3056,13 @@
   // variable will no longer be used.
   if (VD->hasAttr<BlocksAttr>()) 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<AlignedAttr>() &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88295.294485.patch
Type: text/x-patch
Size: 1488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200926/a12fa558/attachment-0001.bin>


More information about the cfe-commits mailing list