https://bugs.llvm.org/show_bug.cgi?id=43856
Bug ID: 43856
Summary: Cast from past-the-end pointer from Derived to Base
invalid inside constant expression
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangb...@nondot.org
Reporter: ldio...@apple.com
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@metafoo.co.uk
Hi,
The following code produces an error with Clang trunk:
$ cat <<EOF | clang++ -xc++ -std=c++17 -
struct Base { };
struct Derived : Base { };
constexpr bool f() {
Derived array[5] = {};
Derived* ptr = array + 5;
Base* base = ptr; // <<<<< error HERE
return true;
}
static_assert(f());
EOF
The error is:
<stdin>:4:16: error: constexpr function never produces a constant
expression [-Winvalid-constexpr]
constexpr bool f() {
^
<stdin>:7:18: note: cannot access base class of pointer past the end of
object
Base* base = ptr;
^
<stdin>:11:15: error: static_assert expression is not an integral constant
expression
static_assert(f());
^~~
<stdin>:7:18: note: cannot access base class of pointer past the end of
object
Base* base = ptr;
^
<stdin>:11:15: note: in call to 'f()'
static_assert(f());
^
I believe this should still be a constant expression because we are not
actually accessing `ptr` (which is indeed past-the-end), we're just casting it
from a Derived class to a Base class.
--
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