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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Dec 2 03:54:19 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 {{}}
----------------
philnik777 wrote:

Please write down what the notes are. We want to check that the compiler generates the expected diagnostics, not that it generates _any_.

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


More information about the libcxx-commits mailing list