re PR c++/49813 ([C++0x] sinh vs asinh vs constexpr)
authorJason Merrill <jason@redhat.com>
Mon, 1 Aug 2011 18:14:29 +0000 (14:14 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 1 Aug 2011 18:14:29 +0000 (14:14 -0400)
PR c++/49813
* semantics.c (potential_constant_expression_1): Allow any builtin.
(morally_constexpr_builtin_function_p): Remove.

From-SVN: r177066

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

index 7f0b24ed53666e987e21372ac031d516ebddebe6..b40b290fb50e21839489d459f93ef8b919eede7f 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-01  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49813
+       * semantics.c (potential_constant_expression_1): Allow any builtin.
+       (morally_constexpr_builtin_function_p): Remove.
+
 2011-07-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/49867
index c44c0efd0ae6259032939b8f58e74985594da039..47b714fc04d78a33d3bd0b300dbc7e8878810691 100644 (file)
@@ -7523,32 +7523,6 @@ check_automatic_or_tls (tree ref)
 }
 #endif
 
-/* Return true if the DECL designates a builtin function that is
-   morally constexpr, in the sense that its parameter types and
-   return type are literal types and the compiler is allowed to
-   fold its invocations.  */
-
-static bool
-morally_constexpr_builtin_function_p (tree decl)
-{
-  tree funtype = TREE_TYPE (decl);
-  tree t;
-
-  if (!is_builtin_fn (decl))
-    return false;
-  if (!literal_type_p (TREE_TYPE (funtype)))
-    return false;
-  for (t = TYPE_ARG_TYPES (funtype); t != NULL ; t = TREE_CHAIN (t))
-    {
-      if (t == void_list_node)
-        return true;
-      if (!literal_type_p (TREE_VALUE (t)))
-        return false;
-    }
-  /* We assume no varargs builtins are suitable.  */
-  return t != NULL;
-}
-
 /* Return true if T denotes a potentially constant expression.  Issue
    diagnostic as appropriate under control of FLAGS.  If WANT_RVAL is true,
    an lvalue-rvalue conversion is implied.
@@ -7656,7 +7630,9 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
                if (builtin_valid_in_constant_expr_p (fun))
                  return true;
                if (!DECL_DECLARED_CONSTEXPR_P (fun)
-                   && !morally_constexpr_builtin_function_p (fun))
+                   /* Allow any built-in function; if the expansion
+                      isn't constant, we'll deal with that then.  */
+                   && !is_builtin_fn (fun))
                  {
                    if (flags & tf_error)
                      {
index 7a5d30f47e98e9cbf76b913dcbdee1e2b56957fe..aa7354b19b98c93597217e64d99f245470779f22 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-01  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49813
+       * g++.dg/cpp0x/constexpr-builtin1.C: New.
+
 2011-08-01  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/49927
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin1.C
new file mode 100644 (file)
index 0000000..b3f5576
--- /dev/null
@@ -0,0 +1,25 @@
+// PR c++/49813
+// { dg-options -std=c++0x }
+
+inline constexpr bool
+isinf(long double __x)
+{ return __builtin_isinf(__x); }
+
+inline constexpr bool
+isinf(double __x)
+{ return __builtin_isinf(__x); }
+
+inline constexpr bool
+isnan(long double __x)
+{ return __builtin_isnan(__x); }
+
+int main()
+{
+  constexpr long double num1 = __builtin_isinf(1.l); // Ok.
+
+  constexpr long double num2 = isinf(1.l);           // Error.
+
+  constexpr double      num3 = isinf(1.);            // Ok.
+
+  constexpr long double num4 = isnan(1.l);           // Ok.
+}