re PR c++/85695 (if constexpr misevaluates typedefed type value)
authorMarek Polacek <polacek@redhat.com>
Tue, 8 May 2018 19:30:57 +0000 (19:30 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 8 May 2018 19:30:57 +0000 (19:30 +0000)
PR c++/85695
* semantics.c (finish_if_stmt_cond): See through typedefs.

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

From-SVN: r260049

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

index 65991150ef0aa775466ea99365cad733d6649987..d80c15d21684c2e2edd5d0b325b69863af2d9db3 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85695
+       * semantics.c (finish_if_stmt_cond): See through typedefs.
+
 2018-05-07  Jason Merrill  <jason@redhat.com>
 
        PR c++/85646 - lambda visibility.
index 2b2b51b2a7e339238e855b3c80e013013d2b8a1c..195286ca7519378792eb07fa116016f5a4f99cbb 100644 (file)
@@ -736,7 +736,7 @@ finish_if_stmt_cond (tree cond, tree if_stmt)
       && !instantiation_dependent_expression_p (cond)
       /* Wait until instantiation time, since only then COND has been
         converted to bool.  */
-      && TREE_TYPE (cond) == boolean_type_node)
+      && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
     {
       cond = instantiate_non_dependent_expr (cond);
       cond = cxx_constant_value (cond, NULL_TREE);
index dc19677d02cb698262f3bfeb645eded36a3684c6..3bfeb894b9b46dd62da15ad955f9e1cd569e2516 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-08  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/85695
+       * g++.dg/cpp1z/constexpr-if22.C: New test.
+
 2018-05-08  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/85693
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if22.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if22.C
new file mode 100644 (file)
index 0000000..76f0c73
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/85695
+// { dg-options -std=c++17 }
+
+template <typename T, T v>
+struct integral_constant {
+    using value_type = T;
+    static constexpr const value_type value = v;
+    constexpr operator value_type (void) const { return value; }
+};
+template <typename T> struct is_trivial
+    : public integral_constant<bool, __is_trivial(T)> {};
+
+template <typename T>
+T clone_object (const T& p)
+{
+    if constexpr (is_trivial<T>::value)
+        return p;
+    else
+        return p.clone();
+}
+int main (void) { return clone_object(0); }