diff options
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/pr79650.C | 20 |
4 files changed, 44 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d362c47..ac6a8e1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-12-14 Jakub Jelinek <jakub@redhat.com> + + PR c++/79650 + * pt.c (convert_nontype_argument): Diagnose + reduced_constant_expression_p expressions that aren't INTEGER_CST. + 2017-12-13 Paolo Carlini <paolo.carlini@oracle.com> PR c++/81061 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 282dd14..69b9535 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6577,7 +6577,19 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) return NULL_TREE; /* else cxx_constant_value complained but gave us a real constant, so go ahead. */ - gcc_assert (TREE_CODE (expr) == INTEGER_CST); + if (TREE_CODE (expr) != INTEGER_CST) + { + /* Some assemble time constant expressions like + (intptr_t)&&lab1 - (intptr_t)&&lab2 or + 4 + (intptr_t)&&var satisfy reduced_constant_expression_p + as we can emit them into .rodata initializers of + variables, yet they can't fold into an INTEGER_CST at + compile time. Refuse them here. */ + gcc_checking_assert (reduced_constant_expression_p (expr)); + error_at (loc, "template argument %qE for type %qT not " + "a constant integer", expr, type); + return NULL_TREE; + } } else return NULL_TREE; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b80b2f2..802146b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-14 Jakub Jelinek <jakub@redhat.com> + + PR c++/79650 + * g++.dg/template/pr79650.C: New test. + 2017-12-14 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> diff --git a/gcc/testsuite/g++.dg/template/pr79650.C b/gcc/testsuite/g++.dg/template/pr79650.C new file mode 100644 index 0000000..72c7814 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr79650.C @@ -0,0 +1,20 @@ +// PR c++/79650 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +typedef __INTPTR_TYPE__ intptr_t; +template<intptr_t> struct A {}; + +void +foo () +{ + static int a, b; +lab1: +lab2: + A<(intptr_t)&&lab1 - (__INTPTR_TYPE__)&&lab2> c; // { dg-error "not a constant integer" } + A<(intptr_t)&&lab1 - (__INTPTR_TYPE__)&&lab1> d; + A<(intptr_t)&a - (intptr_t)&b> e; // { dg-error "is not a constant expression" } + A<(intptr_t)&a - (intptr_t)&a> f; + A<(intptr_t)sizeof(a) + (intptr_t)&a> g; // { dg-error "not a constant integer" } + A<(intptr_t)&a> h; // { dg-error "conversion from pointer type" } +} |