diff --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h --- a/libcxx/include/__memory/allocator.h +++ b/libcxx/include/__memory/allocator.h @@ -80,6 +80,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator<_Tp> > { + static_assert(!is_volatile::type>::value, "std::allocator does not support volatile types"); public: typedef size_t size_type; typedef ptrdiff_t difference_type; @@ -162,6 +163,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::value, allocator > { + static_assert(!is_volatile::type>::value, "std::allocator does not support volatile types"); public: typedef size_t size_type; typedef ptrdiff_t difference_type; diff --git a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: libc++ + +#include + +auto A1 = std::allocator{}; // expected-error@*:* {{std::allocator does not support volatile types}} +auto A2 = std::allocator{}; // expected-error@*:* {{std::allocator does not support volatile types}} + +auto A3 = std::allocator{}; // expected-error@*:* {{std::allocator does not support volatile types}} +auto A4 = std::allocator{}; // expected-error@*:* {{std::allocator does not support volatile types}}