+2020-01-25 Marek Polacek <polacek@redhat.com>
+
+ PR c++/93414 - poor diagnostic for dynamic_cast in constexpr context.
+ * constexpr.c (cxx_eval_dynamic_cast_fn): Add a reference
+ dynamic_cast diagnostic.
+
2020-01-24 Jason Merrill <jason@redhat.com>
PR c++/93400 - ICE with constrained friend.
if (tree t = (TREE_CODE (obj) == COMPONENT_REF
? TREE_OPERAND (obj, 1) : obj))
if (TREE_CODE (t) != FIELD_DECL || !DECL_FIELD_IS_BASE (t))
- return integer_zero_node;
+ {
+ if (reference_p)
+ {
+ if (!ctx->quiet)
+ {
+ error_at (loc, "reference %<dynamic_cast%> failed");
+ inform (loc, "dynamic type %qT of its operand does "
+ "not have a base class of type %qT",
+ objtype, type);
+ }
+ *non_constant_p = true;
+ }
+ return integer_zero_node;
+ }
/* [class.cdtor] When a dynamic_cast is used in a constructor ...
or in a destructor ... if the operand of the dynamic_cast refers
+2020-01-25 Marek Polacek <polacek@redhat.com>
+
+ PR c++/93414 - poor diagnostic for dynamic_cast in constexpr context.
+ * g++.dg/cpp2a/constexpr-dynamic18.C: New test.
+
2020-01-25 Feng Xue <fxue@os.amperecomputing.com>
PR ipa/93166
--- /dev/null
+// PR c++/93414 - poor diagnostic for dynamic_cast in constexpr context.
+// { dg-do compile { target c++2a } }
+// Here 'b' doesn't point/refer to a public base of Derived.
+
+struct Base {
+ constexpr virtual ~Base(){}
+};
+
+struct Derived: Base {
+ constexpr ~Derived(){}
+};
+
+constexpr const Derived& cast(const Base& b) {
+ return dynamic_cast<const Derived&>(b); // { dg-error "reference .dynamic_cast. failed" }
+// { dg-message "dynamic type .const Base. of its operand does not have a base class of type .Derived." "" { target *-*-* } .-1 }
+}
+
+auto test() {
+ static constexpr Base b;
+ constexpr auto res = cast(b);
+ return res;
+}