From: Paolo Carlini Date: Wed, 18 Jan 2012 20:27:23 +0000 (+0000) Subject: re PR c++/51225 ([c++0x] [4.7 Regression] ICE with invalid template parameter) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=55e83c66c7cbe6ac0ef526d7c70462eacde9511d;p=gcc.git re PR c++/51225 ([c++0x] [4.7 Regression] ICE with invalid template parameter) /cp 2012-01-18 Paolo Carlini 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 PR c++/51225 * g++.dg/cpp0x/pr51225.C: New. From-SVN: r183286 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e90f8331204..b0660ce57af 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2012-01-18 Paolo Carlini + + 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 PR c++/51854 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f2b4c8e0319..87ec5f5103e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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), diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index a1b4274bdb1..7793744ae4f 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 352f15d99fd..e79f00b58ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-18 Paolo Carlini + + PR c++/51225 + * g++.dg/cpp0x/pr51225.C: New. + 2012-01-17 Ian Lance Taylor 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 index 00000000000..6fcf8611f9c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr51225.C @@ -0,0 +1,14 @@ +// PR c++/51225 +// { dg-options "-std=c++0x" } + +template struct A {}; + +template void foo() +{ + A a; // { dg-error "not declared|invalid type" } +} + +template struct bar +{ + static constexpr A<1> b = A<1>(x); // { dg-error "not declared" } +};