47 lines · cpp
1// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \2// RUN: -fsafe-buffer-usage-suggestions \3// RUN: -fblocks -verify %s4 5// RUN: %clang -x c++ -frtti -fsyntax-only -fblocks %s 2>&1 | FileCheck --allow-empty %s6// RUN: %clang_cc1 -std=c++11 -fblocks %s 2>&1 | FileCheck --allow-empty %s7// RUN: %clang_cc1 -std=c++20 -fblocks %s 2>&1 | FileCheck --allow-empty %s8// CHECK-NOT: [-Wunsafe-buffer-usage]9 10 11namespace std {12 class type_info;13 class bad_cast;14 class bad_typeid;15}16using size_t = __typeof(sizeof(int));17void *malloc(size_t);18 19void foo(int v) {20}21 22void foo(int *p){}23 24void foo(int, int);25 26void uneval_context_fix() {27 auto p = new int[10]; // expected-warning{{'p' is an unsafe pointer used for buffer access}}28 29 // Warn on the following DREs30 _Generic(1, int: p[2], float: 3); // expected-note{{used in buffer access here}}31 32 // Do not warn for following DREs33 auto q = new int[10];34 foo(sizeof(q[1]), // no-note35 sizeof(decltype(q[1]))); // no-note36 __typeof(q[5]) x; // no-note37 int *r = (int *)malloc(sizeof(q[5])); // no-note38 int y = sizeof(q[5]); // no-note39 __is_pod(__typeof(q[5])); // no-note40 __is_trivially_constructible(__typeof(q[5]), decltype(q[5])); // no-note41 _Generic(q[1], int: 2, float: 3); // no-note42 _Generic(1, int: 2, float: q[3]); // no-note43 decltype(q[2]) var = y; // no-note44 noexcept(q[2]); // no-note45 typeid(q[3]); // no-note46}47