We ICE here because rhstype is null. Since we're looking to see if it's a pointer type, we can just return NULL_TREE if it's null.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-04-04 Marek Polacek <pola...@redhat.com> 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. diff --git gcc/c-family/c-warn.c gcc/c-family/c-warn.c index 4785887c1de..05ea2bf8719 100644 --- gcc/c-family/c-warn.c +++ 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 gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C gcc/testsuite/g++.dg/warn/Waddress-of-packed-member2.C new file mode 100644 index 00000000000..ec6edab2f41 --- /dev/null +++ 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 <typename> +constexpr void *b = a(); // { dg-error "invalid conversion" }