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#include "build/config/clang/unsafe_buffers_buildflags.h" 10 11namespace base { 12 13UNSAFE_BUFFER_USAGE int uses_pointer_as_array(int* i) { 14 return UNSAFE_BUFFERS(i[1]); 15} 16 17void CallToUnsafeBufferFunctionDisallowed() { 18 int arr[] = {1, 2}; 19#if BUILDFLAG(UNSAFE_BUFFERS_WARNING_ENABLED) 20 uses_pointer_as_array(arr); // expected-error {{function introduces unsafe buffer manipulation}} 21#else 22 uses_pointer_as_array(arr); // expected-no-diagnostics: No error when not enabled. 23#endif 24} 25 26} // namespace base 27