https://bugs.llvm.org/show_bug.cgi?id=40089
Bug ID: 40089
Summary: Bad errors if exceeding constexpr iteration limit
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangb...@nondot.org
Reporter: blub...@gmail.com
CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
neeil...@live.com, richard-l...@metafoo.co.uk
Input:
constexpr int x(int y)
{
return y;
}
constexpr int z()
{
for (int i=0;i<0x7fffffff;i++)
if (x(i) != x(i)) return 1;
return 0;
}
template<int e> int ee() { return e; }
int p() { return ee<z()>(); }
Expected: Anything containing
<source>:2:1: note: constexpr evaluation hit maximum step limit; possible
infinite loop?
{
^
<source>:8:21: note: in call to 'x(209714)'
if (x(i) != x(i)) return 1;
^
Actual:
<source>:14:18: error: no matching function for call to 'ee'
int p() { return ee<z()>(); }
^~~~~~~
<source>:12:21: note: candidate template ignored: invalid explicitly-specified
argument for template parameter 'e'
template<int e> int ee() { return e; }
^
and nothing else.
GCC gives much better results:
<source>: In function 'int p()':
<source>:14:26: error: no matching function for call to 'ee<z()>()'
int p() { return ee<z()>(); }
^
<source>:12:21: note: candidate: 'template<int e> int ee()'
template<int e> int ee() { return e; }
^~
<source>:12:21: note: template argument deduction/substitution failed:
<source>:14:22: in 'constexpr' expansion of 'z()'
<source>:7:5: error: 'constexpr' loop iteration count exceeds limit of 262144
(use -fconstexpr-loop-limit= to increase the limit)
for (int i=0;i<0x7fffffff;i++)
^~~
<source>:14:22: note: in template argument for type 'int'
int p() { return ee<z()>(); }
~^~
Bonus: Replace the last line with
template int ee<z()>();
to get bad errors from both Clang and GCC. Alternatively,
constexpr bool w = z();
yields good errors from both; inlining x() also gives good errors. (GCC
mentions -fconstexpr-loop-limit=, but Clang doesn't mention -fconstexpr-steps=;
not sure if that's intentional.)
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs