| 1 |
/* PR middle-end/100684 - spurious -Wnonnull with -O1 on a C++ lambda |
| 2 |
{ dg-do compile { target c++11 } } |
| 3 |
{ dg-options "-Og -Wall -fsanitize=undefined" } */ |
| 4 |
|
| 5 |
#define NONNULL __attribute__ ((nonnull)) |
| 6 |
|
| 7 |
typedef int F (const char *); |
| 8 |
|
| 9 |
__attribute__ ((nonnull)) int f (const char *); |
| 10 |
|
| 11 |
int nowarn_Og () |
| 12 |
{ |
| 13 |
return static_cast<F*>([](const char *s){ return f (s); })("Og"); |
| 14 |
// { dg-bogus "'this' pointer is null" "" { target *-*-* } .-1 } |
| 15 |
} |
| 16 |
|
| 17 |
int warn_Og () |
| 18 |
{ |
| 19 |
return static_cast<F*>([] NONNULL (const char *){ return 0; })(0); |
| 20 |
// { dg-warning "\\\[-Wnonnull" "" { target *-*-* } .-1 } |
| 21 |
} |
| 22 |
|
| 23 |
int warn_Og_inline () |
| 24 |
{ |
| 25 |
const char *p = 0; |
| 26 |
return static_cast<F*>([](const char *s){ return f (s); })(p); |
| 27 |
// { dg-warning "\\\[-Wnonnull" "lambda not inlined" { xfail *-*-* } .-1 } |
| 28 |
} |