Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

warning #3384: expression not folded to a constant due to excessive constexpr function call nesting (possible infinite recursion

Raffael_C_
Beginner
869 Views

Hi,

I recently got the following diagnostic message while compiling some code using Intel Compiler XE2014 Update 1 using the optimization level O1 on Windows:

[cpp]warning #3384: expression not folded to a constant due to excessive constexpr function call nesting (possible infinite recursion)[/cpp]

The particular piece of code that it complains about calls a constexpr function which calls other constexpr functions etc. The calling tree is rather large but it is finite. As far as I understand the compiler is telling me that he was not able to evaluate the constexpr at compile time although he should have been able too. So I guess there is some maximum depth in the call hierarchy which is accepted by the Intel compiler, is there any way to modify this? (It would be really nice if Intel could evaluate the constexpr already at compile time since it should give quite a boost in performance)

Thanks,

Raffael

0 Kudos
3 Replies
Judith_W_Intel
Employee
869 Views

 

The default consexpr call depth limit is 1000. The C++ standard requires at least 512.

You can increase it with the hidden option:

-Qoption,cpp,--max_constexpr_call_depth,number

Example:

bash-3.2$ cat t.cpp

template <int i>
constexpr int foo() { return foo<i-1>(); }

template <>
constexpr int foo<0>() { return 0;}


int main() {
  foo<2000>();
  return 0;
}
bash-3.2$ icl /Qstd=c++11 -c t.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version Mainline Bet
a Build x
Built Jan  2 2014 18:30:10 by jward4 on JWARD4-DESK in D:/workspaces/cfe/dev
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

t.cpp
t.cpp(3): warning #3384: expression not folded to a constant due to excessive co
nstexpr function call nesting (possible infinite recursion)
  constexpr int foo() { return foo<i-1>(); }
                               ^
          detected during:
            instantiation of "int foo<i>() [with i=1746]" at line 3
            instantiation of "int foo<i>() [with i=1747]" at line 3
            instantiation of "int foo<i>() [with i=1748]" at line 3
            instantiation of "int foo<i>() [with i=1749]" at line 3
            instantiation of "int foo<i>() [with i=1750]" at line 3
            [ 245 instantiation contexts not shown ]
            instantiation of "int foo<i>() [with i=1996]" at line 3
            instantiation of "int foo<i>() [with i=1997]" at line 3
            instantiation of "int foo<i>() [with i=1998]" at line 3
            instantiation of "int foo<i>() [with i=1999]" at line 3
            instantiation of "int foo<i>() [with i=2000]" at line 10

etc.

compilation aborted for t.cpp (code -42)

bash-3.2$ icl /Qstd=c++11 -c -Qoption,cpp,--max_constexpr_call_depth,4000 t.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version Mainline Bet
a Build x
Built Jan  2 2014 18:30:10 by jward4 on JWARD4-DESK in D:/workspaces/cfe/dev
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

t.cpp
bash-3.2$

There's also a maximum number of calls which is the maximum number of constexpr function and constructor call
expansions from a single top-level call.  If we reach the maximum, the next call is considered non-foldable, which probably makes the overall
expression non-constant.  The C++11 standard has no specific minimum value.

Our maximum value is 50000 which can be increased with the hidden option:

-Qoption,cpp,--max_constexpr_call_count,number

Judy

0 Kudos
Judith_W_Intel
Employee
869 Views

 

BTW I noticed that GNU has tied this to the -ftemplate-depth switch so I have entered a feature request in our bug tracking system to do that with our Linux compiler (icpc).  Since Microsoft has not yet implemented constexpr I don't know what they are going to do.

0 Kudos
Raffael_C_
Beginner
869 Views

Thanks very much, that resolved the issue :)

0 Kudos
Reply