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: unassignedclangb...@nondot.org
Reporter: m...@mikaelsimonsson.com
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs