From 2e73a89bc9a73ef83b7b87fb65b8293c0ae8b693 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 23 Jan 2018 08:46:05 +0100 Subject: [PATCH] re PR c++/83918 ([c++17] ICE on constexpr eval of datatype involving function and variadic template) PR c++/83918 * tree.c (maybe_wrap_with_location): Use NON_LVALUE_EXPR rather than VIEW_CONVERT_EXPR to wrap CONST_DECLs. * g++.dg/cpp1z/pr83918.C: New test. From-SVN: r256972 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1z/pr83918.C | 32 ++++++++++++++++++++++++++++ gcc/tree.c | 6 ++++-- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr83918.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 507bb52dc82..a1307e34b50 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-01-23 Jakub Jelinek + + PR c++/83918 + * tree.c (maybe_wrap_with_location): Use NON_LVALUE_EXPR rather than + VIEW_CONVERT_EXPR to wrap CONST_DECLs. + 2018-01-22 Jakub Jelinek PR tree-optimization/83957 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 82497ed9641..d22af7ab927 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-23 Jakub Jelinek + + PR c++/83918 + * g++.dg/cpp1z/pr83918.C: New test. + 2018-01-22 Jakub Jelinek PR tree-optimization/83957 diff --git a/gcc/testsuite/g++.dg/cpp1z/pr83918.C b/gcc/testsuite/g++.dg/cpp1z/pr83918.C new file mode 100644 index 00000000000..d4fe82631ed --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/pr83918.C @@ -0,0 +1,32 @@ +// PR c++/83918 +// { dg-do compile } +// { dg-options "-std=c++17" } + +constexpr unsigned +foo (unsigned x, unsigned y) +{ + return x > y ? x : y; +} + +template struct A; +template struct B; +template +struct A , B > +{ + enum : unsigned + { + u = foo (sizeof (S), sizeof (U)), + v = A , B >::w, + w = foo (u, v) + }; +}; + +template <> +struct A , B <>> +{ + enum : unsigned { w = 0 }; +}; + +constexpr static const auto v { A , + B <9,8,7,6,5,4,3,2,1>>::w }; +static_assert (v == sizeof (int)); diff --git a/gcc/tree.c b/gcc/tree.c index b3e93b87eb2..452d3855a77 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -14085,8 +14085,10 @@ maybe_wrap_with_location (tree expr, location_t loc) if (EXCEPTIONAL_CLASS_P (expr)) return expr; - tree_code code = (CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST - ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR); + tree_code code + = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST) + || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr))) + ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR); tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr); /* Mark this node as being a wrapper. */ EXPR_LOCATION_WRAPPER_P (wrapper) = 1; -- 2.30.2