Hi,
So, the issue here is that fold_non_dependent_expr_sfinae checks
potential_constant_expression, and doesn't fold anything which isn't one.
One approach would be to only guard cxx_constant_value with
require_potential_constant_expression within a template.
Thanks. Thus I tried to implement your suggestion with the below, which
indeed passes testing on x86_64-linux. Is it what you had mind?
Thanks,
Paolo.
////////////////////////
/cp
2012-01-18 Paolo Carlini <paolo.carl...@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.carl...@oracle.com>
PR c++/51225
* g++.dg/cpp0x/pr51225.C: New.
Index: testsuite/g++.dg/cpp0x/pr51225.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr51225.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr51225.C (revision 0)
@@ -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" }
+};
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 183273)
+++ cp/typeck2.c (working copy)
@@ -718,8 +718,14 @@ store_init_value (tree decl, tree init, VEC(tree,g
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: cp/pt.c
===================================================================
--- cp/pt.c (revision 183273)
+++ cp/pt.c (working copy)
@@ -5807,6 +5807,9 @@ convert_nontype_argument (tree type, tree expr, ts
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),