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