[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-unsafe-buffer-usage-pragma-misuse.cpp
blob106661491800b7d85279aa715203a31be05517c4
1 // RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
2 // RUN: -fsafe-buffer-usage-suggestions -verify %s
4 void beginUnclosed(int * x) {
5 #pragma clang unsafe_buffer_usage begin
7 #pragma clang unsafe_buffer_usage begin // expected-error{{already inside '#pragma unsafe_buffer_usage'}}
8 x++;
9 #pragma clang unsafe_buffer_usage end
12 void endUnopened(int *x) {
13 #pragma clang unsafe_buffer_usage end // expected-error{{not currently inside '#pragma unsafe_buffer_usage'}}
15 #pragma clang unsafe_buffer_usage begin
16 x++;
17 #pragma clang unsafe_buffer_usage end
20 void wrongOption() {
21 #pragma clang unsafe_buffer_usage start // expected-error{{expected 'begin' or 'end'}}
22 #pragma clang unsafe_buffer_usage close // expected-error{{expected 'begin' or 'end'}}
25 void unclosed(int * p1) {
26 #pragma clang unsafe_buffer_usage begin
27 // End of the included file will not raise the unclosed region warning:
28 #define _INCLUDE_NO_WARN
29 #include "warn-unsafe-buffer-usage-pragma.h"
30 #pragma clang unsafe_buffer_usage end
32 // End of this file raises the warning:
33 #pragma clang unsafe_buffer_usage begin // expected-error{{'#pragma unsafe_buffer_usage' was not ended}}