This patch fixes 79290, a bogus error caused by -Wall trying to figure
out if a component ref expr results a thing that can never be null.
unfortunately, it was looking at a PMF record access, and even though
that;s a RECORD_TYPE, it's not CLASSTYPE because the relevant flag is clear.
Fixed by setting TREE_NO_WARN on the COMPONENT_REF, so we don't go
trying to warn about it.
applied to trunk.
nathan
--
Nathan Sidwell
2017-01-31 Nathan Sidwell <nat...@acm.org>
PR c++/79290
* typeck.c (build_ptrmemfunc_access_expr): Set TREE_NO_WARNING.
PR c++/79290
* g++.dg/warn/pr79290.C: New.
Index: cp/typeck.c
===================================================================
--- cp/typeck.c (revision 245067)
+++ cp/typeck.c (working copy)
@@ -2950,7 +2950,10 @@ build_ptrmemfunc_access_expr (tree ptrme
member = DECL_CHAIN (member))
if (DECL_NAME (member) == member_name)
break;
- return build_simple_component_ref (ptrmem, member);
+ tree res = build_simple_component_ref (ptrmem, member);
+
+ TREE_NO_WARNING (res) = 1;
+ return res;
}
/* Given an expression PTR for a pointer, return an expression
Index: testsuite/g++.dg/warn/pr79290.C
===================================================================
--- testsuite/g++.dg/warn/pr79290.C (revision 0)
+++ testsuite/g++.dg/warn/pr79290.C (working copy)
@@ -0,0 +1,25 @@
+// { dg-additional-options "-Wall" }
+// PR 79290, bogus warning looking inside PMF
+
+struct Song {
+ int get() const ;
+};
+
+typedef int (Song::*PMF_t)() const;
+
+struct SongTag {
+ PMF_t function () const;
+};
+
+
+template<typename T>
+struct Printer {
+ bool Foo(const SongTag &st) {
+ return st.function () == &Song::get;
+ }
+};
+
+void Baz (Printer<int> *p, SongTag const &st)
+{
+ p->Foo (st);
+}