Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sema] Fix volatile check when testing if a return object can be impl…
…icitly moved 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 an 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. Differential Revision: https://reviews.llvm.org/D88295
- Loading branch information
1 parent
6cb1c0c
commit 703038b
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: %clang_cc1 -std=c++20 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s | ||
// RUN: %clang_cc1 -std=c++17 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s | ||
// RUN: %clang_cc1 -std=c++14 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s | ||
// RUN: %clang_cc1 -std=c++11 -emit-llvm -triple x86_64-unknown-linux-gnu -o - %s | FileCheck %s | ||
|
||
// - volatile object in return statement don't match the rule for using move | ||
// operation instead of copy operation. Thus should call the copy constructor | ||
// A(const volatile A &). | ||
// | ||
// - volatile object in return statement also don't match the rule for copy | ||
// elision. Thus the copy constructor A(const volatile A &) cannot be elided. | ||
namespace test_volatile { | ||
class A { | ||
public: | ||
A() {} | ||
~A() {} | ||
A(const volatile A &); | ||
A(volatile A &&); | ||
}; | ||
|
||
A test() { | ||
volatile A a_copy; | ||
// CHECK: call void @_ZN13test_volatile1AC1ERVKS0_ | ||
return a_copy; | ||
} | ||
} // namespace test_volatile |