public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH to add test to cover case RANGE_FOR_STMT
@ 2018-10-12  1:42 Marek Polacek
  2018-11-01 18:06 ` Marek Polacek
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2018-10-12  1:42 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Recently it came up that no test in the testsuite triggers the RANGE_FOR_STMT
case in potential_constant_expression_1.  I came up with this valid test that
tickles that codepath.

I can't use ({ }) instead of a lambda because the constexpr machinery doesn't
handle statement expressions; see default: in cxx_eval_constant_expression.

Tested on x86_64-linux, ok for trunk?

2018-10-11  Marek Polacek  <polacek@redhat.com>

	* g++.dg/cpp1z/constexpr-lambda22.C: New test,

diff --git gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
index e69de29bb2d..8bb473431a5 100644
--- gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
+++ gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
@@ -0,0 +1,20 @@
+// { dg-do compile }
+// { dg-options -std=c++17 }
+
+#define SA(X) static_assert((X),#X)
+
+template<typename>
+constexpr int
+foo ()
+{
+  constexpr int a[] = { 1, 2, 3, 4, 5 };
+  int i = 0;
+  auto j = [&] {
+    for (auto x : a)
+      i++;
+    return i;
+  }();
+  return j;
+}
+
+SA (foo<int>() == 5);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ PATCH to add test to cover case RANGE_FOR_STMT
  2018-10-12  1:42 C++ PATCH to add test to cover case RANGE_FOR_STMT Marek Polacek
@ 2018-11-01 18:06 ` Marek Polacek
  2018-11-01 18:16   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2018-11-01 18:06 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Ping.

On Thu, Oct 11, 2018 at 09:28:38PM -0400, Marek Polacek wrote:
> Recently it came up that no test in the testsuite triggers the RANGE_FOR_STMT
> case in potential_constant_expression_1.  I came up with this valid test that
> tickles that codepath.
> 
> I can't use ({ }) instead of a lambda because the constexpr machinery doesn't
> handle statement expressions; see default: in cxx_eval_constant_expression.
> 
> Tested on x86_64-linux, ok for trunk?
> 
> 2018-10-11  Marek Polacek  <polacek@redhat.com>
> 
> 	* g++.dg/cpp1z/constexpr-lambda22.C: New test,
> 
> diff --git gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
> index e69de29bb2d..8bb473431a5 100644
> --- gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
> +++ gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
> @@ -0,0 +1,20 @@
> +// { dg-do compile }
> +// { dg-options -std=c++17 }
> +
> +#define SA(X) static_assert((X),#X)
> +
> +template<typename>
> +constexpr int
> +foo ()
> +{
> +  constexpr int a[] = { 1, 2, 3, 4, 5 };
> +  int i = 0;
> +  auto j = [&] {
> +    for (auto x : a)
> +      i++;
> +    return i;
> +  }();
> +  return j;
> +}
> +
> +SA (foo<int>() == 5);

Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ PATCH to add test to cover case RANGE_FOR_STMT
  2018-11-01 18:06 ` Marek Polacek
@ 2018-11-01 18:16   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2018-11-01 18:16 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 11/1/18 2:06 PM, Marek Polacek wrote:
> Ping.
> 
> On Thu, Oct 11, 2018 at 09:28:38PM -0400, Marek Polacek wrote:
>> Recently it came up that no test in the testsuite triggers the RANGE_FOR_STMT
>> case in potential_constant_expression_1.  I came up with this valid test that
>> tickles that codepath.
>>
>> I can't use ({ }) instead of a lambda because the constexpr machinery doesn't
>> handle statement expressions; see default: in cxx_eval_constant_expression.
>>
>> Tested on x86_64-linux, ok for trunk?
>>
>> 2018-10-11  Marek Polacek  <polacek@redhat.com>
>>
>> 	* g++.dg/cpp1z/constexpr-lambda22.C: New test,

OK, thanks.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-01 18:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12  1:42 C++ PATCH to add test to cover case RANGE_FOR_STMT Marek Polacek
2018-11-01 18:06 ` Marek Polacek
2018-11-01 18:16   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).