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