From 05564120c6b6e3850faa3586824c298f76cc3985 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 5 Apr 2019 14:56:53 +0000 Subject: [PATCH] PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion. PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion. * c-warn.c (check_address_or_pointer_of_packed_member): Check the type of RHS. * g++.dg/warn/Waddress-of-packed-member2.C: New test. From-SVN: r270166 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-warn.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index ae6b8a7094d..5cce5de1d28 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2019-04-05 Marek Polacek + + PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion. + * c-warn.c (check_address_or_pointer_of_packed_member): Check the type + of RHS. + 2019-04-03 Jason Merrill PR c++/86586 - -fcompare-debug=-Wsign-compare. diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index 4785887c1de..05ea2bf8719 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -2769,7 +2769,7 @@ check_address_or_pointer_of_packed_member (tree type, tree rhs) rhs = TREE_TYPE (rhs); /* Pointer type. */ rhs = TREE_TYPE (rhs); /* Function type. */ rhstype = TREE_TYPE (rhs); - if (!POINTER_TYPE_P (rhstype)) + if (!rhstype || !POINTER_TYPE_P (rhstype)) return NULL_TREE; rvalue = true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e19a1b824e9..4a9fd96ea36 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-04-05 Marek Polacek + + PR c++/89973 - -Waddress-of-packed-member ICE with invalid conversion. + * g++.dg/warn/Waddress-of-packed-member2.C: New test. + 2019-04-05 Richard Biener PR debug/89892 diff --git a/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C b/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C new file mode 100644 index 00000000000..e9bf7cac04c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C @@ -0,0 +1,7 @@ +// PR c++/89973 +// { dg-do compile { target c++14 } } + +constexpr int a(); // { dg-warning "used but never defined" } + +template +constexpr void *b = a(); // { dg-error "invalid conversion" } -- 2.30.2