xref: /aosp_15_r20/external/clang/test/SemaCXX/constexpr-strlen.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify -pedantic
2*67e74705SXin Li 
3*67e74705SXin Li # 1 "/usr/include/string.h" 1 3 4
4*67e74705SXin Li extern "C" {
5*67e74705SXin Li   typedef decltype(sizeof(int)) size_t;
6*67e74705SXin Li   extern size_t strlen(const char *p);
7*67e74705SXin Li }
8*67e74705SXin Li 
9*67e74705SXin Li # 10 "SemaCXX/constexpr-strlen.cpp" 2
10*67e74705SXin Li constexpr int n = __builtin_strlen("hello"); // ok
11*67e74705SXin Li constexpr int m = strlen("hello"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strlen' cannot be used in a constant expression}}
12*67e74705SXin Li 
13*67e74705SXin Li // Make sure we can evaluate a call to strlen.
14*67e74705SXin Li int arr[3]; // expected-note {{here}}
15*67e74705SXin Li int k = arr[strlen("hello")]; // expected-warning {{array index 5}}
16