[libcxx-commits] [libcxx] 902e28d - [libc++] Refactor .compile.fail.cpp tests for std::function

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 14 07:56:22 PST 2022


Author: Louis Dionne
Date: 2022-12-14T10:55:46-05:00
New Revision: 902e28def669bd3f0f45088fd7793b1f2f58286a

URL: https://github.com/llvm/llvm-project/commit/902e28def669bd3f0f45088fd7793b1f2f58286a
DIFF: https://github.com/llvm/llvm-project/commit/902e28def669bd3f0f45088fd7793b1f2f58286a.diff

LOG: [libc++] Refactor .compile.fail.cpp tests for std::function

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

Added: 
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.verify.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.verify.cpp

Modified: 
    

Removed: 
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.compile.fail.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.fail.cpp
    libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.compile.fail.cpp


################################################################################
diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.compile.fail.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.verify.cpp
similarity index 57%
rename from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.compile.fail.cpp
rename to libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.verify.cpp
index 1642fa4585c3b..6c44e0b435f80 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.compile.fail.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.verify.cpp
@@ -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'}}
 }

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.fail.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp
similarity index 100%
rename from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.fail.cpp
rename to libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/deduct_F.verify.cpp

diff  --git a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.compile.fail.cpp b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.verify.cpp
similarity index 51%
rename from libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.compile.fail.cpp
rename to libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.verify.cpp
index 0f8e051d4067c..82871975aa068 100644
--- a/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.compile.fail.cpp
+++ b/libcxx/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.inv/invoke.verify.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++03
+
 // <functional>
 
 // class function<R(ArgTypes...)>
@@ -15,33 +17,11 @@
 #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}}
 }


        


More information about the libcxx-commits mailing list