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. * g++.dg/cpp0x/constexpr-volatile2.C: New test. * g++.dg/cpp0x/pr65327.C: Add dg-error. From-SVN: r267030
This commit is contained in:
parent
6b9ef867ec
commit
3c393a2c01
6 changed files with 32 additions and 4 deletions
|
@ -1,3 +1,11 @@
|
|||
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
|
||||
|
|
|
@ -5476,10 +5476,11 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
|
|||
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))
|
||||
|
|
|
@ -4313,7 +4313,7 @@ decl_maybe_constant_var_p (tree decl)
|
|||
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. */
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
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.
|
||||
|
|
13
gcc/testsuite/g++.dg/cpp0x/constexpr-volatile2.C
Normal file
13
gcc/testsuite/g++.dg/cpp0x/constexpr-volatile2.C
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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" }
|
||||
}
|
|
@ -15,4 +15,4 @@ constexpr volatile int
|
|||
bar ()
|
||||
{
|
||||
return i;
|
||||
}
|
||||
} // { dg-error "lvalue-to-rvalue conversion of a volatile lvalue" }
|
||||
|
|
Loading…
Add table
Reference in a new issue