| 1 |
// RUN: %clang_cc1 -fsyntax-only -Wno-all -Wunsafe-buffer-usage -verify %s -std=c++20 |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -Wno-all -Wunsafe-buffer-usage -verify %s -x c |
| 3 |
// expected-no-diagnostics |
| 4 |
|
| 5 |
typedef struct {} FILE; |
| 6 |
int fprintf( FILE* stream, const char* format, ... ); |
| 7 |
FILE * stderr; |
| 8 |
|
| 9 |
#define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \ |
| 10 |
fprintf(stderr, "AssertMacros: %s, %s file: %s, line: %d, value: %lld\n", \ |
| 11 |
assertion, (message!=0) ? message : "", file, line, (long long) (value)); |
| 12 |
|
| 13 |
|
| 14 |
#define Require(assertion, exceptionLabel) \ |
| 15 |
do \ |
| 16 |
{ \ |
| 17 |
if ( __builtin_expect(!(assertion), 0) ) { \ |
| 18 |
DEBUG_ASSERT_MESSAGE( \ |
| 19 |
"DEBUG_ASSERT_COMPONENT_NAME_STRING", \ |
| 20 |
#assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \ |
| 21 |
goto exceptionLabel; \ |
| 22 |
} \ |
| 23 |
} while ( 0 ) |
| 24 |
|
| 25 |
|
| 26 |
void f(int x, int y) { |
| 27 |
Require(x == y, L1); |
| 28 |
L1: |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
// Test that the analysis will not crash when a conditional expression |
| 33 |
// appears in dependent context: |
| 34 |
#ifdef __cplusplus |
| 35 |
struct Foo { |
| 36 |
static void static_method(int); |
| 37 |
}; |
| 38 |
void conditional_inside_dependent_context(void) { |
| 39 |
auto lambda = [](auto result) { // opens a dependent context |
| 40 |
Foo::static_method(result ? 1 : 2); // no-crash |
| 41 |
}; |
| 42 |
(void)lambda; |
| 43 |
} |
| 44 |
#endif // __cplusplus |