xref: /aosp_15_r20/external/clang/test/SemaCXX/constexpr-steps.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++1y -fsyntax-only -verify %s -DMAX=1234 -fconstexpr-steps 1234
2*67e74705SXin Li // RUN: %clang_cc1 -std=c++1y -fsyntax-only -verify %s -DMAX=10 -fconstexpr-steps 10
3*67e74705SXin Li // RUN: %clang -std=c++1y -fsyntax-only -Xclang -verify %s -DMAX=12345 -fconstexpr-steps=12345
4*67e74705SXin Li 
5*67e74705SXin Li // This takes a total of n + 4 steps according to our current rules:
6*67e74705SXin Li //  - One for the compound-statement that is the function body
7*67e74705SXin Li //  - One for the 'for' statement
8*67e74705SXin Li //  - One for the 'int k = 0;' statement
9*67e74705SXin Li //  - One for each of the n evaluations of the compound-statement in the 'for' body
10*67e74705SXin Li //  - One for the 'return' statemnet
steps(int n)11*67e74705SXin Li constexpr bool steps(int n) {
12*67e74705SXin Li   for (int k = 0; k != n; ++k) {}
13*67e74705SXin Li   return true; // expected-note {{step limit}}
14*67e74705SXin Li }
15*67e74705SXin Li 
16*67e74705SXin Li static_assert(steps((MAX - 4)), ""); // ok
17*67e74705SXin Li static_assert(steps((MAX - 3)), ""); // expected-error {{constant}} expected-note{{call}}
18