2018-08-21 Marek Polacek <polacek@redhat.com>
+ PR c++/65043
+ * call.c (standard_conversion): Set check_narrowing.
+ * typeck2.c (check_narrowing): Use CP_INTEGRAL_TYPE_P rather
+ than comparing with INTEGER_TYPE.
+
* cp-tree.h: Fix typo.
2018-08-20 David Malcolm <dmalcolm@redhat.com>
conv->rank = cr_pbool;
if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
conv->bad_p = true;
+ if (flags & LOOKUP_NO_NARROWING)
+ conv->check_narrowing = true;
return conv;
}
if (const_only && !TREE_CONSTANT (init))
return ok;
- if (TREE_CODE (type) == INTEGER_TYPE
+ if (CP_INTEGRAL_TYPE_P (type)
&& TREE_CODE (ftype) == REAL_TYPE)
ok = false;
else if (INTEGRAL_OR_ENUMERATION_TYPE_P (ftype)
+2018-08-21 Marek Polacek <polacek@redhat.com>
+
+ PR c++/65043
+ * g++.dg/concepts/pr67595.C: Add dg-warning.
+ * g++.dg/cpp0x/Wnarrowing11.C: New test.
+ * g++.dg/cpp0x/Wnarrowing12.C: New test.
+ * g++.dg/cpp0x/rv-cast5.C: Add static_cast.
+
2018-08-21 Ed Schonberg <schonberg@adacore.com>
* gnat.dg/expr_func7.adb, gnat.dg/expr_func7.ads: New testcase.
template <class X> concept bool semiregular = allocatable<X>;
template <class X> concept bool readable = requires{requires semiregular<X>};
template <class> int weak_input_iterator = requires{{0}->readable};
-template <class X> bool input_iterator{weak_input_iterator<X>};
+template <class X> bool input_iterator{weak_input_iterator<X>}; // { dg-warning "narrowing conversion" }
template <class X> bool forward_iterator{input_iterator<X>};
template <class X> bool bidirectional_iterator{forward_iterator<X>};
template <class X>
--- /dev/null
+// PR c++/65043
+// { dg-do compile { target c++11 } }
+
+struct X
+{
+ X(bool) { }
+};
+
+struct Y
+{
+ Y(char) { }
+};
+
+struct Z
+{
+ Z(char16_t) { }
+};
+
+struct W
+{
+ W(char32_t) { }
+};
+
+int main()
+{
+ X x{1.2}; // { dg-error "narrowing conversion" }
+ Y y{1.2}; // { dg-error "narrowing conversion" }
+ Z z{1.2}; // { dg-error "narrowing conversion" }
+ W w{1.2}; // { dg-error "narrowing conversion" }
+}
--- /dev/null
+// PR c++/65043
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wnarrowing" }
+
+struct X
+{
+ X(bool) { }
+};
+
+struct Y
+{
+ Y(char) { }
+};
+
+struct Z
+{
+ Z(char16_t) { }
+};
+
+struct W
+{
+ W(char32_t) { }
+};
+
+int main()
+{
+ double d = 1.2;
+ X x{d}; // { dg-warning "narrowing conversion" }
+ Y y{d}; // { dg-warning "narrowing conversion" }
+ Z z{d}; // { dg-warning "narrowing conversion" }
+ W w{d}; // { dg-warning "narrowing conversion" }
+}
int main()
{
- hold<bool&&>{42}();
+ hold<bool&&>{static_cast<bool>(42)}();
}