Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit a3d727b

Browse files
committed
volatile types are not trivially copyable.
PR17123. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190484 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6c3eb6b commit a3d727b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/AST/Type.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,15 +1097,18 @@ bool QualType::isTriviallyCopyableType(ASTContext &Context) const {
10971097
}
10981098
}
10991099

1100-
// C++0x [basic.types]p9
1100+
// C++11 [basic.types]p9
11011101
// Scalar types, trivially copyable class types, arrays of such types, and
1102-
// cv-qualified versions of these types are collectively called trivial
1103-
// types.
1102+
// non-volatile const-qualified versions of these types are collectively
1103+
// called trivially copyable types.
11041104

11051105
QualType CanonicalType = getCanonicalType();
11061106
if (CanonicalType->isDependentType())
11071107
return false;
11081108

1109+
if (CanonicalType.isVolatileQualified())
1110+
return false;
1111+
11091112
// Return false for incomplete types after skipping any incomplete array types
11101113
// which are expressly allowed by the standard and thus our API.
11111114
if (CanonicalType->isIncompleteType())

lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,8 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult,
10381038
return ExprError();
10391039
}
10401040

1041-
if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context)) {
1041+
if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
1042+
!AtomTy->isScalarType()) {
10421043
// For GNU atomics, require a trivially-copyable type. This is not part of
10431044
// the GNU atomics specification, but we enforce it for sanity.
10441045
Diag(DRE->getLocStart(), diag::err_atomic_op_needs_trivial_copy)

test/SemaCXX/type-traits.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,9 @@ void is_trivially_copyable2()
10721072
int t31[F(__is_trivially_copyable(SuperNonTrivialStruct))];
10731073
int t32[F(__is_trivially_copyable(NonTCStruct))];
10741074
int t33[F(__is_trivially_copyable(ExtDefaulted))];
1075+
1076+
int t34[T(__is_trivially_copyable(const int))];
1077+
int t35[F(__is_trivially_copyable(volatile int))];
10751078
}
10761079

10771080
struct CStruct {

0 commit comments

Comments
 (0)