diff options
author | Jason Merrill <jason@redhat.com> | 2013-02-13 12:56:28 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2013-02-13 12:56:28 -0500 |
commit | 58b922f813ea1b1eb87c0a6a050546ac27e78c1b (patch) | |
tree | 9944829e810dc52bf8503c3e5058a3e60cca42c7 /gcc | |
parent | d0d9cf0ebf69940ed0b95b7b3644553913126286 (diff) | |
download | gcc-58b922f813ea1b1eb87c0a6a050546ac27e78c1b.zip gcc-58b922f813ea1b1eb87c0a6a050546ac27e78c1b.tar.gz gcc-58b922f813ea1b1eb87c0a6a050546ac27e78c1b.tar.bz2 |
re PR c++/55993 ([C++11] derived-to-base conversion fails in constant expression)
PR c++/55993
* semantics.c (cxx_fold_indirect_ref): Handle empty bases at
non-zero offsets, too.
From-SVN: r196023
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-empty6.C | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ddd0aa0..977d245 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-02-13 Jason Merrill <jason@redhat.com> + PR c++/55993 + * semantics.c (cxx_fold_indirect_ref): Handle empty bases at + non-zero offsets, too. + PR c++/56155 * decl.c (build_enumerator): Always convert the value to a fixed underlying type. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3415828..30c8c52 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7448,6 +7448,15 @@ cxx_fold_indirect_ref (location_t loc, tree type, tree op0, bool *empty_base) return build4_loc (loc, ARRAY_REF, type, op00, op01, NULL_TREE, NULL_TREE); } + /* Also handle conversion to an empty base class, which + is represented with a NOP_EXPR. */ + else if (is_empty_class (type) + && CLASS_TYPE_P (op00type) + && DERIVED_FROM_P (type, op00type)) + { + *empty_base = true; + return op00; + } /* ((foo *)&struct_with_foo_field)[1] => COMPONENT_REF */ else if (RECORD_OR_UNION_TYPE_P (op00type)) { diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-empty6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty6.C new file mode 100644 index 0000000..be9a6c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty6.C @@ -0,0 +1,11 @@ +// PR c++/55993 +// { dg-do compile { target c++11 } } + +struct A {}; +struct B:A {}; +struct C:A {}; +struct D:B,C {}; + +constexpr D d {}; +constexpr const C& e=d; // OK +constexpr auto f=static_cast<const C&>(d); // FAIL |