re PR c++/64603 (bogus error "no matching function for call to ..." with templates)
authorJason Merrill <jason@redhat.com>
Wed, 21 Jan 2015 21:56:34 +0000 (16:56 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 21 Jan 2015 21:56:34 +0000 (16:56 -0500)
PR c++/64603
* constexpr.c (cxx_eval_constant_expression): Only shortcut
constant CONSTRUCTORs.

From-SVN: r219973

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

index 526742c0bcebe42d0bdc2d5c6b4ae989ce411f6d..6e3a2e566fab78fa898d8b434df500264eb882db 100644 (file)
@@ -1,5 +1,9 @@
 2015-01-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/64603
+       * constexpr.c (cxx_eval_constant_expression): Only shortcut
+       constant CONSTRUCTORs.
+
        PR c++/64647
        * constexpr.c (ensure_literal_type_for_constexpr_object): Don't
        give a hard error in a template instantiation.
index decc84d301ff9fcf81183eb3568cc981d645549b..7853d377849bbeeef2276b59bf4d9f549a192c07 100644 (file)
@@ -2943,9 +2943,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
        *overflow_p = true;
       return t;
     }
-  if (TREE_CODE (t) != NOP_EXPR
-      && reduced_constant_expression_p (t))
-    return fold (t);
 
   switch (TREE_CODE (t))
     {
@@ -3315,6 +3312,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
       break;
 
     case CONSTRUCTOR:
+      if (TREE_CONSTANT (t))
+       /* Don't re-process a constant CONSTRUCTOR, but do fold it to
+          VECTOR_CST if applicable.  */
+       return fold (t);
       r = cxx_eval_bare_aggregate (ctx, t, lval,
                                   non_constant_p, overflow_p);
       break;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-sizeof1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-sizeof1.C
new file mode 100644 (file)
index 0000000..d9a032b
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/64603
+// { dg-do compile { target c++11 } }
+
+template <int i> constexpr int find_longest_name()
+{
+  return sizeof("Main") - 1;
+}
+
+template <int i, int l = find_longest_name<i>()> void create_all_loggers()
+{}
+
+int main()
+{
+  create_all_loggers<1>();
+}