[llvm-bugs] [Bug 40089] New: Bad errors if exceeding constexpr iteration limit

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 18 11:12:25 PST 2018


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: unassignedclangbugs at nondot.org
          Reporter: blubban at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181218/5e1f805d/attachment-0001.html>


More information about the llvm-bugs mailing list