• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This is a "No Compile Test" suite.
6// http://dev.chromium.org/developers/testing/no-compile-tests
7
8#include "base/compiler_specific.h"
9
10namespace base {
11
12UNSAFE_BUFFER_USAGE int uses_pointer_as_array(int* i) {
13  return UNSAFE_BUFFERS(i[1]);
14}
15
16void CallToUnsafeBufferFunctionDisallowed() {
17  int arr[] = {1, 2};
18#ifdef UNSAFE_BUFFERS_BUILD
19  uses_pointer_as_array(arr);  // expected-error {{function introduces unsafe buffer manipulation}}
20#else
21  uses_pointer_as_array(arr);  // expected-no-diagnostics: No error when not enabled.
22#endif
23}
24
25}  // namespace base
26