mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 08:36:41 +00:00

Extract included parts in the following tests to separate header files: - SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span-overload.cpp - SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp Removed the included part in the following tests as it is not useful: - SemaCXX/warn-unsafe-buffer-usage-warning-unevaluated-context.cpp
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
|
|
// RUN: -fsafe-buffer-usage-suggestions \
|
|
// RUN: -fblocks -verify %s
|
|
|
|
// RUN: %clang -x c++ -frtti -fsyntax-only -fblocks %s 2>&1 | FileCheck --allow-empty %s
|
|
// RUN: %clang_cc1 -std=c++11 -fblocks %s 2>&1 | FileCheck --allow-empty %s
|
|
// RUN: %clang_cc1 -std=c++20 -fblocks %s 2>&1 | FileCheck --allow-empty %s
|
|
// CHECK-NOT: [-Wunsafe-buffer-usage]
|
|
|
|
|
|
namespace std {
|
|
class type_info;
|
|
class bad_cast;
|
|
class bad_typeid;
|
|
}
|
|
using size_t = __typeof(sizeof(int));
|
|
void *malloc(size_t);
|
|
|
|
void foo(int v) {
|
|
}
|
|
|
|
void foo(int *p){}
|
|
|
|
void foo(int, int);
|
|
|
|
void uneval_context_fix() {
|
|
auto p = new int[10]; // expected-warning{{'p' is an unsafe pointer used for buffer access}}
|
|
|
|
// Warn on the following DREs
|
|
_Generic(1, int: p[2], float: 3); // expected-note{{used in buffer access here}}
|
|
|
|
// Do not warn for following DREs
|
|
auto q = new int[10];
|
|
foo(sizeof(q[1]), // no-note
|
|
sizeof(decltype(q[1]))); // no-note
|
|
__typeof(q[5]) x; // no-note
|
|
int *r = (int *)malloc(sizeof(q[5])); // no-note
|
|
int y = sizeof(q[5]); // no-note
|
|
__is_pod(__typeof(q[5])); // no-note
|
|
__is_trivially_constructible(__typeof(q[5]), decltype(q[5])); // no-note
|
|
_Generic(q[1], int: 2, float: 3); // no-note
|
|
_Generic(1, int: 2, float: q[3]); // no-note
|
|
decltype(q[2]) var = y; // no-note
|
|
noexcept(q[2]); // no-note
|
|
typeid(q[3]); // no-note
|
|
}
|