diff --git a/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp b/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp index fa71d5f725c2..166e50919e78 100644 --- a/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp +++ b/build/clang-plugin/tests/TestNoRefcountedInsideLambdas.cpp @@ -2,6 +2,12 @@ #define MOZ_STRONG_REF #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit"))) +// Ensure that warnings about returning stack addresses of local variables are +// errors, so our `expected-error` annotations below work correctly. +#if __cplusplus >= 201703L +#pragma GCC diagnostic error "-Wreturn-stack-address" +#endif + struct RefCountedBase { void AddRef(); void Release(); @@ -394,7 +400,11 @@ void e() { auto e1 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&](R* argptr) { // expected-error{{address of stack memory associated with local variable 'ptr' returned}} +#else return ([&](R* argptr) { +#endif R* localptr; ptr->method(); argptr->method(); @@ -404,7 +414,11 @@ void e() { auto e2 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&](SmartPtr argsp) { // expected-error{{address of stack memory associated with local variable 'sp' returned}} +#else return ([&](SmartPtr argsp) { +#endif SmartPtr localsp; sp->method(); argsp->method(); @@ -414,7 +428,11 @@ void e() { auto e3 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&](R* argptr) { // expected-error{{address of stack memory associated with local variable 'ptr' returned}} +#else return ([&](R* argptr) { +#endif R* localptr; take(ptr); take(argptr); @@ -424,7 +442,11 @@ void e() { auto e4 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&](SmartPtr argsp) { // expected-error{{address of stack memory associated with local variable 'sp' returned}} +#else return ([&](SmartPtr argsp) { +#endif SmartPtr localsp; take(sp); take(argsp); @@ -514,7 +536,11 @@ void e() { auto e14 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&ptr](R* argptr) { // expected-error{{address of stack memory associated with local variable 'ptr' returned}} +#else return ([&ptr](R* argptr) { +#endif R* localptr; ptr->method(); argptr->method(); @@ -524,7 +550,11 @@ void e() { auto e15 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&sp](SmartPtr argsp) { // expected-error{{address of stack memory associated with local variable 'sp' returned}} +#else return ([&sp](SmartPtr argsp) { +#endif SmartPtr localsp; sp->method(); argsp->method(); @@ -534,7 +564,11 @@ void e() { auto e16 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&ptr](R* argptr) { // expected-error{{address of stack memory associated with local variable 'ptr' returned}} +#else return ([&ptr](R* argptr) { +#endif R* localptr; take(ptr); take(argptr); @@ -544,7 +578,11 @@ void e() { auto e17 = []() { R* ptr; SmartPtr sp; +#if __cplusplus >= 201703L + return ([&sp](SmartPtr argsp) { // expected-error{{address of stack memory associated with local variable 'sp' returned}} +#else return ([&sp](SmartPtr argsp) { +#endif SmartPtr localsp; take(sp); take(argsp);