return true;
if (TREE_THIS_VOLATILE (t) && want_rval
- && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (t)))
+ && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (t))
+ && !NULLPTR_TYPE_P (TREE_TYPE (t)))
{
if (flags & tf_error)
constexpr_error (loc, fundef_p, "lvalue-to-rvalue conversion of "
tree type = TREE_TYPE (decl);
if (!VAR_P (decl))
return false;
- if (DECL_DECLARED_CONSTEXPR_P (decl) && !TREE_THIS_VOLATILE (decl))
+ if (DECL_DECLARED_CONSTEXPR_P (decl)
+ && (!TREE_THIS_VOLATILE (decl) || NULLPTR_TYPE_P (type)))
return true;
if (DECL_HAS_VALUE_EXPR_P (decl))
/* A proxy isn't constant. */
--- /dev/null
+// PR c++/118661
+// { dg-do compile { target c++11 } }
+
+using nullptr_t = decltype (nullptr);
+union U { int i; nullptr_t n; };
+constexpr U u = { 42 };
+static_assert (u.n == nullptr, "");
+
+#if __cplusplus >= 201402L
+constexpr nullptr_t
+foo ()
+{
+ union U { int i; nullptr_t n; } u = { 42 };
+ return u.n;
+}
+#endif
--- /dev/null
+// PR c++/118661
+// { dg-do compile { target c++11 } }
+
+using nullptr_t = decltype (nullptr);
+constexpr volatile nullptr_t a = {};
+constexpr nullptr_t b = a;
+
+constexpr nullptr_t
+foo ()
+{
+#if __cplusplus >= 201402L
+ volatile nullptr_t c = {};
+ return c;
+#else
+ return nullptr;
+#endif
+}
+
+static_assert (b == nullptr, "");
+static_assert (foo () == nullptr, "");