OSDN Git Service

/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 18 Jan 2012 20:27:23 +0000 (20:27 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 18 Jan 2012 20:27:23 +0000 (20:27 +0000)
2012-01-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51225
* typeck2.c (store_init_value): Within a template guard
cxx_constant_value with require_potential_constant_expression.
* pt.c (convert_nontype_argument): Likewise.

/testsuite
2012-01-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51225
* g++.dg/cpp0x/pr51225.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183286 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr51225.C [new file with mode: 0644]

index e90f833..b0660ce 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51225
+       * typeck2.c (store_init_value): Within a template guard
+       cxx_constant_value with require_potential_constant_expression.
+       * pt.c (convert_nontype_argument): Likewise.
+
 2012-01-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/51854
index f2b4c8e..87ec5f5 100644 (file)
@@ -5807,6 +5807,9 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
          if (complain & tf_error)
            {
              int errs = errorcount, warns = warningcount;
+             if (processing_template_decl
+                 && !require_potential_constant_expression (expr))
+               return NULL_TREE;
              expr = cxx_constant_value (expr);
              if (errorcount > errs || warningcount > warns)
                inform (EXPR_LOC_OR_HERE (expr),
index a1b4274..7793744 100644 (file)
@@ -718,8 +718,14 @@ store_init_value (tree decl, tree init, VEC(tree,gc)** cleanups, int flags)
       value = fold_non_dependent_expr (value);
       value = maybe_constant_init (value);
       if (DECL_DECLARED_CONSTEXPR_P (decl))
-       /* Diagnose a non-constant initializer for constexpr.  */
-       value = cxx_constant_value (value);
+       {
+         /* Diagnose a non-constant initializer for constexpr.  */
+         if (processing_template_decl
+             && !require_potential_constant_expression (value))
+           value = error_mark_node;
+         else
+           value = cxx_constant_value (value);
+       }
       const_init = (reduced_constant_expression_p (value)
                    || error_operand_p (value));
       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = const_init;
index 352f15d..e79f00b 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51225
+       * g++.dg/cpp0x/pr51225.C: New.
+
 2012-01-17  Ian Lance Taylor  <iant@google.com>
 
        PR go/50656
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr51225.C b/gcc/testsuite/g++.dg/cpp0x/pr51225.C
new file mode 100644 (file)
index 0000000..6fcf861
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/51225
+// { dg-options "-std=c++0x" }
+
+template<int> struct A {};
+
+template<typename> void foo()
+{
+  A<int(x)> a; // { dg-error "not declared|invalid type" }
+}
+
+template<typename> struct bar
+{
+  static constexpr A<1> b = A<1>(x); // { dg-error "not declared" }
+};