[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
Fri Sep 25 05:09:36 PDT 2020


nullptr.cpp created this revision.
nullptr.cpp added reviewers: Quuxplusone, rsmith, erik.pilkington.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
nullptr.cpp requested review of this revision.

In C++11 standard, to become implicitly movable, the expression in return
statement should be a non-volatile automatic object. CWG1579 changed the rule
to require that the expression only needs to be a automatic object. C++14
standard and C++17 standard kept this rule unchanged. C++20 standard changed
the rule back to require the expression be a non-volatile automatic object.
This should be a typo in standards, and `VD` should be non-volatile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88295

Files:
  clang/lib/Sema/SemaStmt.cpp


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.294286.patch
Type: text/x-patch
Size: 690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200925/f226adc4/attachment.bin>


More information about the cfe-commits mailing list