[libcxx-commits] [libcxx] [libc++] Uniformly require complete types in vector member functions (PR #211110)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 21 13:58:29 PDT 2026
================
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// This test ensures that we diagnose when an incomplete type is used in one of
+// vector's methods. The Standard requires that to be the case, and we want to
+// uniformly produce an error for that. Note that producing the same diagnostic
+// in all cases is difficult, but we at least want to fail to fight back against
+// Hyrum's law.
+
+#include <vector>
+
+struct Incomplete;
+
+void f(std::vector<Incomplete>& v) {
+ (void)v.empty(); // expected-error@*:* {{}}
----------------
ldionne wrote:
This is more difficult to test than I anticipated.
This test currently happens to pass because we produce errors, but the errors are not all static asserts. In fact, most of them are other, non `static_assert` errors.
Furthermore, if I remove the `__require_complete` call from `empty()` (which is arguably the only one that needs something), this test still passes because some of these statements produce more than one error.
So, I'm not certain how to best test this. One test per file would technically work, but there's no way I can convince myself to do that.
https://github.com/llvm/llvm-project/pull/211110
More information about the libcxx-commits
mailing list