Commit adc06f45 by Marek Polacek Committed by Marek Polacek

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.

	* g++.dg/cpp0x/constexpr-conv3.C: New test.
	* g++.dg/cpp0x/constexpr-conv4.C: New test.

From-SVN: r270178
parent 6464d9b1
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> 2019-04-05 Martin Sebor <msebor@redhat.com>
PR bootstrap/89980 PR bootstrap/89980
......
...@@ -6837,6 +6837,19 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) ...@@ -6837,6 +6837,19 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type) else if (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
|| cxx_dialect >= cxx17) || 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 /* C++17: A template-argument for a non-type template-parameter shall
be a converted constant expression (8.20) of the type of the be a converted constant expression (8.20) of the type of the
template-parameter. */ 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> 2019-04-05 Martin Sebor <msebor@redhat.com>
PR bootstrap/89980 PR bootstrap/89980
......
// 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>();
}
// 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>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment