+2018-12-11 Marek Polacek <polacek@redhat.com>
+
+ PR c++/86608 - reading constexpr volatile variable.
+ * constexpr.c (potential_constant_expression_1): Check want_rval
+ instead of checking if we have a decl.
+ * decl2.c (decl_maybe_constant_var_p): Don't consider volatile
+ constexpr variables as maybe constant.
+
2018-12-11 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (grokvardecl): Add location_t parameter and use it
available, so we don't bother with switch tracking. */
return true;
- if (TREE_THIS_VOLATILE (t) && !DECL_P (t))
+ if (TREE_THIS_VOLATILE (t) && want_rval)
{
if (flags & tf_error)
- error_at (loc, "expression %qE has side-effects", t);
+ error_at (loc, "lvalue-to-rvalue conversion of a volatile lvalue "
+ "%qE with type %qT", t, TREE_TYPE (t));
return false;
}
if (CONSTANT_CLASS_P (t))
tree type = TREE_TYPE (decl);
if (!VAR_P (decl))
return false;
- if (DECL_DECLARED_CONSTEXPR_P (decl))
+ if (DECL_DECLARED_CONSTEXPR_P (decl) && !TREE_THIS_VOLATILE (decl))
return true;
if (DECL_HAS_VALUE_EXPR_P (decl))
/* A proxy isn't constant. */
+2018-12-11 Marek Polacek <polacek@redhat.com>
+
+ PR c++/86608 - reading constexpr volatile variable.
+ * g++.dg/cpp0x/constexpr-volatile2.C: New test.
+ * g++.dg/cpp0x/pr65327.C: Add dg-error.
+
2018-12-11 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/pr53037-4.C: Test the first two locations too.
--- /dev/null
+// PR c++/86608
+// { dg-do compile { target c++11 } }
+
+template<typename T, T v> struct X {};
+
+int
+main ()
+{
+ static constexpr volatile int a = 3;
+ constexpr volatile int b = 2;
+ return (sizeof(X<decltype(a), a>) // { dg-error "lvalue-to-rvalue conversion of a volatile lvalue" }
+ + sizeof(X<decltype(b), b>)); // { dg-error "lvalue-to-rvalue conversion of a volatile lvalue" }
+}
bar ()
{
return i;
-}
+} // { dg-error "lvalue-to-rvalue conversion of a volatile lvalue" }