diff options
-rw-r--r-- | gcc/c-family/c-pretty-print.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/pr101515.C | 18 |
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index dac1775..71a0cb5 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -1889,6 +1889,12 @@ c_fold_indirect_ref_for_warn (location_t loc, tree type, tree op, = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (field))); if (upos <= off && off < upos + el_sz) { + /* The C++ pretty printers print scope of the FIELD_DECLs, + so punt if it is something that can't be printed. */ + if (c_dialect_cxx ()) + if (tree scope = get_containing_scope (field)) + if (TYPE_P (scope) && TYPE_NAME (scope) == NULL_TREE) + break; tree cop = build3_loc (loc, COMPONENT_REF, TREE_TYPE (field), op, field, NULL_TREE); off = off - upos; diff --git a/gcc/testsuite/g++.dg/warn/pr101515.C b/gcc/testsuite/g++.dg/warn/pr101515.C new file mode 100644 index 0000000..f3c58b8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr101515.C @@ -0,0 +1,18 @@ +// PR c++/101515 +// { dg-do compile } +// { dg-options "-O1 -Wuninitialized" } + +struct S { int j; }; +struct T : public S { virtual void h () {} }; +struct U { void (*ptr) (); }; +typedef void (S::*sp) (); + +int +main () +{ + T t; + sp x; + U *xp = (U *) &x; + if (xp->ptr != ((void (*) ()) (sizeof (void *)))) // { dg-warning "is used uninitialized" } + return 1; +} |