[libcxx-commits] [libcxx] [libc++] Diagnoses insufficiently aligned pointers for std::assume_aligned during constant evaluation (PR #73775)

Rajveer Singh Bharadwaj via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 3 04:08:00 PST 2023


================
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// #include <memory>
+
+// template<size_t N, class T>
+// [[nodiscard]] constexpr T* assume_aligned(T* ptr);
+
+// Diagnose insufficiently aligned pointers during constant evaluation.
+// ADDITIONAL_COMPILE_FLAGS: -Xclang -verify-ignore-unexpected=error -Xclang -verify-ignore-unexpected=warning
+
+#include <memory>
+
+template <size_t Size>
+constexpr bool test() {
+  auto data  = new char[1];
+  auto data2 = std::assume_aligned<2>(data); // expected-note {{}}
+  delete[] data2;
+
+  return true;
+}
+
+static_assert(test<1>()); // expected-note {{}}
----------------
Rajveer100 wrote:

Yeah, I was figuring that out so I left it empty temporarily.

https://github.com/llvm/llvm-project/pull/73775


More information about the libcxx-commits mailing list