+2019-04-05 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87145 - bogus error converting class type in template arg list.
+ * pt.c (convert_nontype_argument): Don't call
+ build_converted_constant_expr if it could involve calling a conversion
+ function with a instantiation-dependent constructor as its argument.
+
2019-04-05 Martin Sebor <msebor@redhat.com>
PR bootstrap/89980
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
|| cxx_dialect >= cxx17)
{
+ /* Calling build_converted_constant_expr might create a call to
+ a conversion function with a value-dependent argument, which
+ could invoke taking the address of a temporary representing
+ the result of the conversion. */
+ if (COMPOUND_LITERAL_P (expr)
+ && CONSTRUCTOR_IS_DEPENDENT (expr)
+ && MAYBE_CLASS_TYPE_P (expr_type)
+ && TYPE_HAS_CONVERSION (expr_type))
+ {
+ expr = build1 (IMPLICIT_CONV_EXPR, type, expr);
+ IMPLICIT_CONV_EXPR_NONTYPE_ARG (expr) = true;
+ return expr;
+ }
/* C++17: A template-argument for a non-type template-parameter shall
be a converted constant expression (8.20) of the type of the
template-parameter. */
+2019-04-05 Marek Polacek <polacek@redhat.com>
+
+ PR c++/87145 - bogus error converting class type in template arg list.
+ * g++.dg/cpp0x/constexpr-conv3.C: New test.
+ * g++.dg/cpp0x/constexpr-conv4.C: New test.
+
2019-04-05 Martin Sebor <msebor@redhat.com>
PR bootstrap/89980
--- /dev/null
+// PR c++/87145
+// { dg-do compile { target c++11 } }
+
+template<typename T, T t> struct integral_constant {
+ static constexpr T value = t;
+};
+
+enum class Enum : unsigned {};
+
+struct Pod {
+ unsigned val;
+
+ constexpr operator Enum() const {
+ return static_cast<Enum>(val);
+ }
+};
+
+template<unsigned N>
+constexpr void foo() {
+ using Foo = integral_constant<Enum, Pod{N}>;
+}
+
+int main() {
+ foo<2>();
+}
--- /dev/null
+// PR c++/87145
+// { dg-do compile { target c++11 } }
+
+struct S {
+ int val;
+
+ constexpr operator int() const {
+ return static_cast<int>(val);
+ }
+};
+
+template<int N>
+struct F { };
+
+template<unsigned N>
+constexpr void foo() {
+ F<int{N}> f;
+ F<S{N}> f2;
+}
+
+int
+main()
+{
+ foo<2>();
+}