8sa1-gcc/gcc/testsuite/g++.dg/cpp0x/constexpr-data2.C
Marek Polacek ed4f2c001a re PR c++/57891 (No diagnostic of narrowing conversion in non-type template argument)
PR c++/57891
	* call.c (struct conversion): Add check_narrowing_const_only.
	(build_converted_constant_expr): Set check_narrowing and
	check_narrowing_const_only.  Give error if expr is error node.
	(convert_like_real): Pass it to check_narrowing.
	* cp-tree.h (check_narrowing): Add a default parameter.
	* decl.c (compute_array_index_type): Use input_location instead of
	location_of.
	* pt.c (convert_nontype_argument): Return NULL_TREE if tf_error.
	* typeck2.c (check_narrowing): Don't warn for instantiation-dependent
	expressions.  Call maybe_constant_value instead of
	fold_non_dependent_expr.  Don't mention { } in diagnostic.  Only check
	narrowing for constants if CONST_ONLY.

	* g++.dg/cpp0x/Wnarrowing6.C: New test.
	* g++.dg/cpp0x/Wnarrowing7.C: New test.
	* g++.dg/cpp0x/Wnarrowing8.C: New test.
	* g++.dg/cpp0x/Wnarrowing9.C: New test.
	* g++.dg/cpp0x/Wnarrowing10.C: New test.
	* g++.dg/cpp0x/constexpr-47969.C: Adjust dg-error.
	* g++.dg/cpp0x/constexpr-ex2.C: Likewise.
	* g++.dg/cpp0x/constexpr-targ.C: Likewise.
	* g++.dg/cpp0x/scoped_enum2.C: Likewise.
	* g++.dg/ext/stmtexpr15.C: Likewise.
	* g++.dg/gomp/pr47963.C: Likewise.
	* g++.dg/init/new37.C: Likewise.
	* g++.dg/init/new43.C: Likewise.
	* g++.dg/other/fold1.C: Likewise.
	* g++.dg/parse/array-size2.C: Likewise.
	* g++.dg/template/dependent-name3.C: Likewise.
	* g++.dg/cpp0x/constexpr-data2.C: Add dg-error.
	* g++.dg/other/vrp1.C: Likewise.
	* g++.dg/template/char1.C: Likewise.

From-SVN: r263523
2018-08-13 23:12:11 +00:00

47 lines
976 B
C

// { dg-do compile { target c++11 } }
template<typename _Tp, _Tp v>
struct A3
{
typedef _Tp value_type;
typedef A3<value_type,v> type;
static constexpr value_type value = v;
constexpr operator value_type() { return value; }
};
// Partial specialization.
template<typename _Tp, _Tp* v>
struct A3<_Tp*, v>
{
typedef _Tp* value_type;
typedef A3<value_type,v> type;
static constexpr value_type value = v;
constexpr operator value_type() { return value; }
};
// Explicit specialization.
template<>
struct A3<unsigned short, 0>
{
typedef unsigned short value_type;
typedef A3<value_type, 0> type;
static constexpr value_type value = 0;
constexpr operator value_type() { return value; }
};
// Explicitly instantiate.
template struct A3<int, 415>;
// Extern explicitly instantiate.
extern template struct A3<int, 510>;
// Use.
A3<int, 1111> a31;
A3<char, 9999> a32; // { dg-error "narrowing conversion" }