diff options
| author | James Y Knight <jyknight@google.com> | 2019-12-03 23:32:57 -0500 |
|---|---|---|
| committer | James Y Knight <jyknight@google.com> | 2019-12-04 15:12:17 -0500 |
| commit | 90fce46fa6c9ccec86f642be0a75da2d0a5b11c1 (patch) | |
| tree | 14959e616a4d695f876942bac5e44ac0d3334933 /clang/test | |
| parent | 975a43512709a9e989dea11d2fefab9212e3a4f4 (diff) | |
| download | bcm5719-llvm-90fce46fa6c9ccec86f642be0a75da2d0a5b11c1.tar.gz bcm5719-llvm-90fce46fa6c9ccec86f642be0a75da2d0a5b11c1.zip | |
Fix crash-on-invalid-code in lambda constant evaluation.
If the lambda used 'this' without without capturing it, an error was
emitted, but the constant evaluator would still attempt to lookup the
capture, and failing to find it, dereference a null pointer.
This only happens in C++17 (as that's when lambdas were made
potentially-constexpr). Therefore, I also updated the
lambda-expressions.cpp test to run in both C++14 and C++17 modes.
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaCXX/lambda-expressions.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index 5fff855102f..0f4edc4d1f3 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -fblocks %s +// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s +// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks %s namespace std { class type_info; }; @@ -12,6 +13,7 @@ namespace ExplicitCapture { void ImplicitThisCapture() { [](){(void)Member;}; // expected-error {{'this' cannot be implicitly captured in this context}} + const int var = [](){(void)Member; return 0;}(); // expected-error {{'this' cannot be implicitly captured in this context}} [&](){(void)Member;}; [this](){(void)Member;}; @@ -105,7 +107,7 @@ namespace SpecialMembers { a = static_cast<decltype(a)&&>(a); // expected-error {{copy assignment operator is implicitly deleted}} } struct P { - P(const P&) = delete; // expected-note 2{{deleted here}} + P(const P&) = delete; //expected-note {{deleted here}} // expected-cxx14-note {{deleted here}} }; struct Q { ~Q() = delete; // expected-note {{deleted here}} @@ -118,8 +120,8 @@ namespace SpecialMembers { }; void g(P &p, Q &q, R &r) { // FIXME: The note attached to the second error here is just amazingly bad. - auto pp = [p]{}; // expected-error {{deleted constructor}} expected-error {{deleted copy constructor of '(lambda}} - // expected-note@-1 {{copy constructor of '' is implicitly deleted because field '' has a deleted copy constructor}} + auto pp = [p]{}; // expected-error {{deleted constructor}} expected-cxx14-error {{deleted copy constructor of '(lambda}} + // expected-cxx14-note@-1 {{copy constructor of '' is implicitly deleted because field '' has a deleted copy constructor}} auto qq = [q]{}; // expected-error {{deleted function}} expected-note {{because}} auto a = [r]{}; // expected-note 2{{here}} @@ -365,7 +367,7 @@ namespace PR18128 { int (*f())[true ? 1 : ([=]{ return n; }(), 0)]; // expected-error@-1 {{non-local lambda expression cannot have a capture-default}} // expected-error@-2 {{invalid use of non-static data member 'n'}} - // expected-error@-3 {{a lambda expression may not appear inside of a constant expression}} + // expected-cxx14-error@-3 {{a lambda expression may not appear inside of a constant expression}} int g(int k = ([=]{ return n; }(), 0)); // expected-error@-1 {{non-local lambda expression cannot have a capture-default}} // expected-error@-2 {{invalid use of non-static data member 'n'}} @@ -596,8 +598,13 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType { using ExpectedTypeU = void (*)(T&); struct X { +#if __cplusplus > 201402L + friend constexpr auto T::operator()(int) const; + friend constexpr T::operator ExpectedTypeT() const noexcept; +#else friend auto T::operator()(int) const; friend T::operator ExpectedTypeT() const; +#endif // FIXME: The first of these should match. The second should not. template<typename T> |

