From 461a67fa15370a9ec88f8f8a240bf7c123bb2029 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:11:37 +0000 Subject: Vendor import of clang trunk r321017: https://llvm.org/svn/llvm-project/cfe/trunk@321017 --- test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp | 142 +++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp') diff --git a/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp b/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp index dc3adca62fd3..eaed45acd11b 100644 --- a/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp +++ b/test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp @@ -1380,3 +1380,145 @@ XT xt{}; void PR33318(int i) { [&](auto) { static_assert(&i != nullptr, ""); }(0); // expected-warning 2{{always true}} expected-note {{instantiation}} } + +// Check to make sure that we don't capture when member-calls are made to members that are not of 'this' class. +namespace PR34266 { +// https://bugs.llvm.org/show_bug.cgi?id=34266 +namespace ns1 { +struct A { + static void bar(int) { } + static void bar(double) { } +}; + +struct B +{ + template + auto f() { + auto L = [=] { + T{}.bar(3.0); + T::bar(3); + + }; + ASSERT_NO_CAPTURES(L); + return L; + }; +}; + +void test() { + B{}.f(); +} +} // end ns1 + +namespace ns2 { +struct A { + static void bar(int) { } + static void bar(double) { } +}; + +struct B +{ + using T = A; + auto f() { + auto L = [=](auto a) { + T{}.bar(a); + T::bar(a); + + }; + ASSERT_NO_CAPTURES(L); + return L; + }; +}; + +void test() { + B{}.f()(3.0); + B{}.f()(3); +} +} // end ns2 + +namespace ns3 { +struct A { + void bar(int) { } + static void bar(double) { } +}; + +struct B +{ + using T = A; + auto f() { + auto L = [=](auto a) { + T{}.bar(a); + T::bar(a); // This call ignores the instance member function because the implicit object argument fails to convert. + + }; + ASSERT_NO_CAPTURES(L); + return L; + }; +}; + +void test() { + B{}.f()(3.0); + B{}.f()(3); +} + +} // end ns3 + + +namespace ns4 { +struct A { + void bar(int) { } + static void bar(double) { } +}; + +struct B : A +{ + using T = A; + auto f() { + auto L = [=](auto a) { + T{}.bar(a); + T::bar(a); + + }; + // just check to see if the size if >= 2 bytes (which should be the case if we capture anything) + ASSERT_CLOSURE_SIZE(L, 2); + return L; + }; +}; + +void test() { + B{}.f()(3.0); + B{}.f()(3); +} + +} // end ns4 + +namespace ns5 { +struct A { + void bar(int) { } + static void bar(double) { } +}; + +struct B +{ + template + auto f() { + auto L = [&](auto a) { + T{}.bar(a); + T::bar(a); + + }; + + ASSERT_NO_CAPTURES(L); + return L; + }; +}; + +void test() { + B{}.f()(3.0); + B{}.f()(3); +} + +} // end ns5 + + + +} // end PR34266 -- cgit v1.2.3