PR c++/84421 - type-dependent if constexpr
authorJason Merrill <jason@redhat.com>
Fri, 16 Feb 2018 16:44:17 +0000 (11:44 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 16 Feb 2018 16:44:17 +0000 (11:44 -0500)
* semantics.c (finish_if_stmt_cond): Check
type_dependent_expression_p.

From-SVN: r257744

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C [new file with mode: 0644]

index ee08e689b4ea7e0d812e88d2b33ade0538507ae6..17af63328ed1e610aa8aa0e9f83f4239d1d37369 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-16  Jason Merrill  <jason@redhat.com>
+
+       PR c++/84421 - type-dependent if constexpr
+       * semantics.c (finish_if_stmt_cond): Check type_dependent_expression_p.
+
 2018-02-16  Nathan Sidwell  <nathan@acm.org>
 
        Deprecate -ffriend-injection.
index f0cee68e46f454dd667e83d3e1867ff2c6c68420..35569d0cb0d8e4ec0c616751d03a9cd11edc7574 100644 (file)
@@ -731,6 +731,7 @@ finish_if_stmt_cond (tree cond, tree if_stmt)
 {
   cond = maybe_convert_cond (cond);
   if (IF_STMT_CONSTEXPR_P (if_stmt)
+      && !type_dependent_expression_p (cond)
       && require_constant_expression (cond)
       && !value_dependent_expression_p (cond))
     {
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C
new file mode 100644 (file)
index 0000000..f6cc39a
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/84421
+// { dg-options -std=c++17 }
+
+struct A{
+  constexpr operator bool() const { return true; }
+};
+
+int main(){
+  auto f = [](auto v){
+    if constexpr(v){}
+  };
+  A a;
+  f(a);
+}