[libc++] Refactor .compile.fail.cpp tests for std::function
authorLouis Dionne <ldionne.2@gmail.com>
Fri, 25 Nov 2022 19:20:04 +0000 (14:20 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Wed, 14 Dec 2022 15:55:46 +0000 (10:55 -0500)
Some of those .compile.fail.cpp tests had become incorrect and they
were not testing anything. In general, .compile.fail.cpp tests are
bad because they make it way too easy to write garbage tests. Indeed,
the test could fail to compile due to any reason whatsoever (even a
typo) and it would appear to work correctly.

Differential Revision: https://reviews.llvm.org/D138731

libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.verify.cpp [moved from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.compile.fail.cpp with 57% similarity]
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp [moved from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.fail.cpp with 100% similarity]
libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.verify.cpp [moved from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.compile.fail.cpp with 51% similarity]

@@ -6,21 +6,19 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03
-// XFAIL: c++11, c++14
+// UNSUPPORTED: c++03, c++11, c++14
 
 // <functional>
+//
+// Make sure we can't initialize a std::function using an allocator (http://wg21.link/p0302r1).
+// These constructors were removed in C++17.
 
 #include <functional>
-#include <type_traits>
-
-#include "test_macros.h"
+#include <memory>
 
 struct S : public std::function<void()> { using function::function; };
 
-int main(int, char**) {
-   S f1( [](){} );
-   S f2(std::allocator_arg, std::allocator<int>{}, f1);
-
-  return 0;
+void f() {
+  S f1( [](){} );
+  S f2(std::allocator_arg, std::allocator<int>{}, f1); // expected-error {{no matching constructor for initialization of 'S'}}
 }
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++03
+
 // <functional>
 
 // class function<R(ArgTypes...)>
 #include <functional>
 #include <cassert>
 
-// member data pointer:  cv qualifiers should transfer from argument to return type
-
-struct A_int_1
-{
-    A_int_1() : data_(5) {}
-
-    int data_;
-};
-
-void
-test_int_1()
-{
-    // member data pointer
-    {
-        int A_int_1::*fp = &A_int_1::data_;
-        A_int_1 a;
-        std::function<int& (const A_int_1*)> r2(fp);
-        const A_int_1* ap = &a;
-        assert(r2(ap) == 6);
-        r2(ap) = 7;
-        assert(r2(ap) == 7);
-    }
-}
+// member data pointer: cv qualifiers should transfer from argument to return type
 
-int main(int, char**)
-{
-    test_int_1();
+struct Foo { int data; };
 
-  return 0;
+void f() {
+    int Foo::*fp = &Foo::data;
+    std::function<int& (const Foo*)> r2(fp); // expected-error {{no matching constructor for initialization of}}
 }