Message ID | 55DF5684.8050607@gmail.com |
---|---|
State | New |
Headers | show |
Ping. On 08/27/2015 09:27 PM, Mikhail Maltsev wrote: > Hi. > This patch fixes a rejects-valid bug related to volatile-qualified arguments of > constexpr functions. This is essentially a one-line change in constexpr.c. > Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk? > > gcc/cp/ChangeLog: > > 2015-08-25 Mikhail Maltsev <maltsevm@gmail.com> > > PR c++/67333 > * constexpr.c (potential_constant_expression_1): Do not reject > volatile-qualified values, if there is no lvalue-to-rvalue conversion. > > gcc/testsuite/ChangeLog: > > 2015-08-25 Mikhail Maltsev <maltsevm@gmail.com> > > PR c++/67333 > * g++.dg/cpp0x/constexpr-67333.C: New test. > * g++.dg/cpp1y/constexpr-67333.C: New test. >
PING. On 08/27/2015 09:27 PM, Mikhail Maltsev wrote: > Hi. > This patch fixes a rejects-valid bug related to volatile-qualified arguments of > constexpr functions. This is essentially a one-line change in constexpr.c. > Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk? > > gcc/cp/ChangeLog: > > 2015-08-25 Mikhail Maltsev <maltsevm@gmail.com> > > PR c++/67333 > * constexpr.c (potential_constant_expression_1): Do not reject > volatile-qualified values, if there is no lvalue-to-rvalue conversion. > > gcc/testsuite/ChangeLog: > > 2015-08-25 Mikhail Maltsev <maltsevm@gmail.com> > > PR c++/67333 > * g++.dg/cpp0x/constexpr-67333.C: New test. > * g++.dg/cpp1y/constexpr-67333.C: New test. >
Hi, sorry for the slow response. Please feel free to ping once a week.
On 08/27/2015 02:27 PM, Mikhail Maltsev wrote:
> + if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval))
Why the !DECL_P check? Pulling the value out of a volatile INDIRECT_REF
is just as problematic as from a variable.
Jason
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1eacb8b..f4ee727 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4006,7 +4006,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, return false; if (t == NULL_TREE) return true; - if (TREE_THIS_VOLATILE (t)) + if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval)) { if (flags & tf_error) error ("expression %qE has side-effects", t); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C new file mode 100644 index 0000000..885ece6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C @@ -0,0 +1,29 @@ +// PR c++/67333 +// { dg-do compile { target c++11 } } + +template <int N> +struct integral_constant +{ + static constexpr int value = N; +}; + +template <typename T, int S> +constexpr int lengthof (const volatile T (&)[S]) +{ + return S; +} + +template <typename T, int S> +constexpr int valueof (const volatile T (&s)[S]) // { dg-error "has side-effects" } +{ + return s[0]; +} + +int main () +{ + volatile int meow[4] {}; + integral_constant<lengthof (meow)>::value; // OK + integral_constant<valueof (meow)>::value; // { dg-error "in a constant expression" } + return 0; +} + diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C new file mode 100644 index 0000000..7e3ef21 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C @@ -0,0 +1,26 @@ +// PR c++/67333 +// { dg-do compile { target c++14 } } + +template <int N> +struct integral_constant +{ + static constexpr int value = N; +}; + +constexpr int decl (int x) +{ + volatile int v = x; + return x; +} + +constexpr int use (int x) +{ + volatile int v = x; + return v; +} // { dg-error "has side-effects" } + +int main() +{ + integral_constant<decl (2)>::value; // OK + integral_constant<use (2)>::value; // { dg-error "in a constant expression" } +}