This valid test started to be accepted with r265789, which removed the following checks. I wonder if we want to remove them in gcc 8, or just leave them in place. For trunk I'm going to add the new test.
@@ -6985,27 +7071,10 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) itself value-dependent, since what we want here is its address. */; else { - if (!DECL_P (expr)) - { - if (complain & tf_error) - error ("%qE is not a valid template argument for type %qT " - "because it is not an object with linkage", - expr, type); - return NULL_TREE; - } - - /* DR 1155 allows internal linkage in C++11 and up. */ - linkage_kind linkage = decl_linkage (expr); - if (linkage < (cxx_dialect >= cxx11 ? lk_internal : lk_external)) - { - if (complain & tf_error) - error ("%qE is not a valid template argument for type %qT " - "because object %qD does not have linkage", - expr, type, expr); - return NULL_TREE; - } - expr = build_address (expr); + + if (invalid_tparm_referent_p (type, expr, complain)) + return NULL_TREE; } if (!same_type_p (type, TREE_TYPE (expr))) Tested on x86_64-linux, applying to trunk. 2019-04-24 Marek Polacek <pola...@redhat.com> PR c++/90236 * g++.dg/cpp1z/nontype-auto16.C: New test. diff --git gcc/testsuite/g++.dg/cpp1z/nontype-auto16.C gcc/testsuite/g++.dg/cpp1z/nontype-auto16.C new file mode 100644 index 00000000000..695bb11d780 --- /dev/null +++ gcc/testsuite/g++.dg/cpp1z/nontype-auto16.C @@ -0,0 +1,13 @@ +// PR c++/90236 +// { dg-do compile { target c++17 } } + +struct foo { }; + +template <const auto &> void fnc() { } + +void +test() +{ + static constexpr foo a; + fnc<a>(); +}