]> granicus.if.org Git - clang/commit
constexpr: check for overflow in pointer subtraction.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Feb 2012 08:10:20 +0000 (08:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 1 Feb 2012 08:10:20 +0000 (08:10 +0000)
commit15efc4d597a47e6ba5794d4fd8d561bf6947233c
treef2e85b5cbf295eb13d69dc66f47805230c83ec76
parentab14ae2ab16088b6a7f69eac6e152c3e9f9ea01b
constexpr: check for overflow in pointer subtraction.

This is a mess. According to the C++11 standard, pointer subtraction only has
undefined behavior if the difference of the array indices does not fit into a
ptrdiff_t.

However, common implementations effectively perform a char* subtraction first,
and then divide the result by the element size, which can cause overflows in
some cases. Those cases are not considered to be undefined behavior by this
change; perhaps they should be.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149490 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/ExprConstant.cpp
test/CXX/expr/expr.const/p2-0x.cpp