aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2014-08-22 19:12:46 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2014-08-22 19:12:46 +0000
commitb65eff46797a017f6ff524c87e8513948073c089 (patch)
treec86a4aafb8a1a26f9bd4278787e962a264ab6afb /gcc
parent6c6d76bec50feb6f9d9455d968c05de121b591d8 (diff)
downloadgcc-b65eff46797a017f6ff524c87e8513948073c089.zip
gcc-b65eff46797a017f6ff524c87e8513948073c089.tar.gz
gcc-b65eff46797a017f6ff524c87e8513948073c089.tar.bz2
re PR c++/57709 (-Wshadow is too strict / has false positives)
gcc/cp/ChangeLog: 2014-08-22 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/57709 * name-lookup.c (pushdecl_maybe_friend_1): Do not warn if a declaration shadows a function declaration, unless the former declares a function, pointer to function or pointer to member function, because this is a common and valid case in real-world code. * cp-tree.h (TYPE_PTRFN_P,TYPE_REFFN_P,TYPE_PTRMEMFUNC_P): Improve description. gcc/testsuite/ChangeLog: 2014-08-22 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c++/57709 * g++.dg/Wshadow.C: New test. From-SVN: r214357
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog11
-rw-r--r--gcc/cp/cp-tree.h7
-rw-r--r--gcc/cp/name-lookup.c21
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/Wshadow.C15
5 files changed, 52 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 649941c..2ea2665 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,14 @@
+2014-08-22 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/57709
+ * name-lookup.c (pushdecl_maybe_friend_1): Do not warn if a
+ declaration shadows a function declaration, unless the former
+ declares a function, pointer to function or pointer to member
+ function, because this is a common and valid case in real-world
+ code.
+ * cp-tree.h (TYPE_PTRFN_P,TYPE_REFFN_P,TYPE_PTRMEMFUNC_P):
+ Improve description.
+
2014-08-22 Jason Merrill <jason@redhat.com>
PR c++/62129
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 34373b7..81c7fd6 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3558,18 +3558,17 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
&& !(TREE_CODE (TREE_TYPE (NODE)) == FUNCTION_TYPE \
|| TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE))
-/* Returns true if NODE is a pointer to function. */
+/* Returns true if NODE is a pointer to function type. */
#define TYPE_PTRFN_P(NODE) \
(TYPE_PTR_P (NODE) \
&& TREE_CODE (TREE_TYPE (NODE)) == FUNCTION_TYPE)
-/* Returns true if NODE is a reference to function. */
+/* Returns true if NODE is a reference to function type. */
#define TYPE_REFFN_P(NODE) \
(TREE_CODE (NODE) == REFERENCE_TYPE \
&& TREE_CODE (TREE_TYPE (NODE)) == FUNCTION_TYPE)
-/* Nonzero for _TYPE node means that this type is a pointer to member
- function type. */
+/* Returns true if NODE is a pointer to member function type. */
#define TYPE_PTRMEMFUNC_P(NODE) \
(TREE_CODE (NODE) == RECORD_TYPE \
&& TYPE_PTRMEMFUNC_FLAG (NODE))
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 6e779a6..ebcbb5c 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1239,9 +1239,24 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
if (member && !TREE_STATIC (member))
{
- /* Location of previous decl is not useful in this case. */
- warning (OPT_Wshadow, "declaration of %qD shadows a member of 'this'",
- x);
+ if (BASELINK_P (member))
+ member = BASELINK_FUNCTIONS (member);
+ member = OVL_CURRENT (member);
+
+ /* Do not warn if a variable shadows a function, unless
+ the variable is a function or a pointer-to-function. */
+ if (TREE_CODE (member) != FUNCTION_DECL
+ || TREE_CODE (x) == FUNCTION_DECL
+ || TYPE_PTRFN_P (TREE_TYPE (x))
+ || TYPE_PTRMEMFUNC_P (TREE_TYPE (x)))
+ {
+ if (warning_at (input_location, OPT_Wshadow,
+ "declaration of %qD shadows a member of %qT",
+ x, current_nonlambda_class_type ())
+ && DECL_P (member))
+ inform (DECL_SOURCE_LOCATION (member),
+ "shadowed declaration is here");
+ }
}
else if (oldglobal != NULL_TREE
&& (VAR_P (oldglobal)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a6415d6..ce3e30e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-08-22 Manuel López-Ibáñez <manu@gcc.gnu.org>
+
+ PR c++/57709
+ * g++.dg/Wshadow.C: New test.
+
2014-08-22 Steven Bosscher <steven@gcc.gnu.org>
PR fortran/62135
diff --git a/gcc/testsuite/g++.dg/Wshadow.C b/gcc/testsuite/g++.dg/Wshadow.C
new file mode 100644
index 0000000..482d2f0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/Wshadow.C
@@ -0,0 +1,15 @@
+// { dg-do compile }
+// { dg-options "-Wshadow" }
+// PR c++/57709
+class C {
+ int both_var; // { dg-message "declaration" }
+ void var_and_method(void) {} // { dg-message "declaration" }
+ void m() {
+ int
+ both_var, // { dg-warning "shadows" }
+ var_and_method;
+ }
+ void m2() {
+ void (C::*var_and_method)(void); // { dg-warning "shadows" }
+ }
+};