[llvm-bugs] [Bug 42000] New: __builtin_sub_overflow reports invalid overflow in constexpr context
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri May 24 00:50:49 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42000
Bug ID: 42000
Summary: __builtin_sub_overflow reports invalid overflow in
constexpr context
Product: clang
Version: trunk
Hardware: PC
OS: FreeBSD
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: m at mikaelsimonsson.com
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
This code fails to compile:
#include <cstdint>
constexpr bool overflows(uint8_t a, int b)
{
uint8_t diff = 0;
return __builtin_sub_overflow(a, b, &diff);
}
int main()
{
static_assert(!overflows(255, 100));
return 0;
}
11:5: error: static_assert failed due to requirement '!overflows(255, 100)'
static_assert(!overflows(255, 100));
^ ~~~~~~~~~~~~~~~~~~~~
1 error generated.
But this code compiles and runs without triggering the assert:
#include <cassert>
#include <cstdint>
inline bool overflows(uint8_t a, int b)
{
uint8_t diff = 0;
return __builtin_sub_overflow(a, b, &diff);
}
int main()
{
assert(!overflows(255, 100));
return 0;
}
Tested with godbolt.org: clang version 9.0.0 (trunk 361583)
--
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/20190524/ac06157c/attachment.html>
More information about the llvm-bugs
mailing list