* [C++ PATCH] PR c++/89576 - if constexpr of lambda capture.
@ 2019-03-06 18:50 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2019-03-06 18:50 UTC (permalink / raw)
To: gcc-patches
Now that we're doing implicit lambda capture in templates, we see x here as
the lambda capture. maybe_convert_cond was doing nothing in a template, so
we never called mark_rvalue_use on x. As part of the broad move toward
doing more processing of non-dependent expressions, let's do this
conversion.
Tested x86_64-pc-linux-gnu, applying to trunk.
* semantics.c (maybe_convert_cond): Do convert a non-dependent
condition in a template.
* typeck.c (condition_conversion): Handle being called in a
template.
---
gcc/cp/semantics.c | 4 ++--
gcc/cp/typeck.c | 9 ++++-----
gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C | 2 +-
gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C | 11 +++++++++++
gcc/cp/ChangeLog | 8 ++++++++
5 files changed, 26 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c03e4ef247c..2573b77f6d6 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -646,10 +646,10 @@ maybe_convert_cond (tree cond)
return NULL_TREE;
/* Wait until we instantiate templates before doing conversion. */
- if (processing_template_decl)
+ if (type_dependent_expression_p (cond))
return cond;
- if (warn_sequence_point)
+ if (warn_sequence_point && !processing_template_decl)
verify_sequence_points (cond);
/* Do the conversion. */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 1bf9ad88141..8367497b539 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5867,18 +5867,17 @@ cp_truthvalue_conversion (tree expr)
return c_common_truthvalue_conversion (input_location, expr);
}
-/* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */
+/* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. This
+ is a low-level function; most callers should use maybe_convert_cond. */
tree
condition_conversion (tree expr)
{
tree t;
- /* Anything that might happen in a template should go through
- maybe_convert_cond. */
- gcc_assert (!processing_template_decl);
t = perform_implicit_conversion_flags (boolean_type_node, expr,
tf_warning_or_error, LOOKUP_NORMAL);
- t = fold_build_cleanup_point_expr (boolean_type_node, t);
+ if (!processing_template_decl)
+ t = fold_build_cleanup_point_expr (boolean_type_node, t);
return t;
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
index 1dd8beab89c..49c7b7abb63 100644
--- a/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C
@@ -7,5 +7,5 @@ constexpr int foo (int) { return 2; }
template <typename>
void a()
{
- if constexpr(foo) { };
+ if constexpr(foo) { }; // { dg-error "overloaded" }
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C
new file mode 100644
index 00000000000..8bfde6c1bdb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if28.C
@@ -0,0 +1,11 @@
+// PR c++/89576
+// { dg-do compile { target c++17 } }
+
+template <class T>
+void foo()
+{
+ constexpr int x = 0;
+ [&] {
+ if constexpr (x) {}
+ };
+}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d2cb7fd1132..f889b253f5a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-06 Jason Merrill <jason@redhat.com>
+
+ PR c++/89576 - if constexpr of lambda capture.
+ * semantics.c (maybe_convert_cond): Do convert a non-dependent
+ condition in a template.
+ * typeck.c (condition_conversion): Handle being called in a
+ template.
+
2019-03-05 Jason Merrill <jason@redhat.com>
* class.c (is_really_empty_class): Add ignore_vptr parm.
base-commit: ad0ce1a5e76e19a5222cb0a529a245d8a7991114
--
2.20.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-03-06 18:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-06 18:50 [C++ PATCH] PR c++/89576 - if constexpr of lambda capture 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).