[llvm-bugs] [Bug 38534] New: Poor diagnostic for assertion failure during constexpr invocation

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 12 04:28:47 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38534

            Bug ID: 38534
           Summary: Poor diagnostic for assertion failure during constexpr
                    invocation
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvmbugs at contacts.eelis.net
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Consider:

  constexpr int f(int i)
  {
      assert(i > 3);
      return i * 2;
  }

This works great:

  static_assert(f(4) == 8); // ok!

Less great is the diagnostic given in case the i > 3 assertion fails:

  static_assert(f(1) == 2); // produces:

----------------------------
<source>:11:15: error: static_assert expression is not an integral constant
expression
static_assert(f(1) == 2);
              ^~~~~~~~~
<source>:5:5: note: non-constexpr function '__assert_fail' cannot be used in a
constant expression
    assert(i > 3);
    ^
/usr/include/assert.h:95:9: note: expanded from macro 'assert'
      : __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION))
        ^
<source>:11:15: note: in call to 'f(1)'
static_assert(f(1) == 2);
              ^
/usr/include/assert.h:69:13: note: declared here
extern void __assert_fail (const char *__assertion, const char *__file,
            ^
----------------------------

I understand where all the noise about constant expressions and the
__assert_fail function and the assert macro comes from, but I think we can
serve users better by emitting a diagnostic that directly states the /real/
problem right away: "assertion i > 3 failed". :)

-- 
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/20180812/1dcba85a/attachment.html>


More information about the llvm-bugs mailing list