diff mbox

C++ PATCH for c++/55993 (wrong error with constexpr)

Message ID 511BA1FC.8090104@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 13, 2013, 2:23 p.m. UTC
When we added empty base handling to the ADDR_EXPR case in 
cxx_fold_indirect_ref, we forgot to add it to the POINTER_PLUS_EXPR case 
as well.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit ed30015624f7d3f396e11fd5d96b548348a74688
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Feb 12 23:12:10 2013 -0500

    	PR c++/55993
    	* semantics.c (cxx_fold_indirect_ref): Handle empty bases at
    	non-zero offsets, too.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index e31ae30..59a50f2 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7440,6 +7440,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