summaryrefslogtreecommitdiff
path: root/gcc/cp/name-lookup.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/name-lookup.c')
-rw-r--r--gcc/cp/name-lookup.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 9e84a1b1f2e..e574c271194 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1195,19 +1195,41 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend)
nowarn = true;
}
- if (warn_shadow && !nowarn)
+ if ((warn_shadow
+ || warn_shadow_local
+ || warn_shadow_compatible_local)
+ && !nowarn)
{
bool warned;
+ enum opt_code warning_code;
+ /* If '-Wshadow=compatible-local' is specified without other
+ -Wshadow= flags, we will warn only when the type of the
+ shadowing variable (i.e. x) can be converted to that of
+ the shadowed parameter (oldlocal). The reason why we only
+ check if x's type can be converted to oldlocal's type
+ (but not the other way around) is because when users
+ accidentally shadow a parameter, more than often they
+ would use the variable thinking (mistakenly) it's still
+ the parameter. It would be rare that users would use the
+ variable in the place that expects the parameter but
+ thinking it's a new decl. */
+ if (warn_shadow)
+ warning_code = OPT_Wshadow;
+ else if (can_convert (TREE_TYPE (oldlocal), TREE_TYPE (x),
+ tf_none))
+ warning_code = OPT_Wshadow_compatible_local;
+ else
+ warning_code = OPT_Wshadow_local;
if (TREE_CODE (oldlocal) == PARM_DECL)
- warned = warning_at (input_location, OPT_Wshadow,
+ warned = warning_at (input_location, warning_code,
"declaration of %q#D shadows a parameter", x);
else if (is_capture_proxy (oldlocal))
- warned = warning_at (input_location, OPT_Wshadow,
+ warned = warning_at (input_location, warning_code,
"declaration of %qD shadows a lambda capture",
x);
else
- warned = warning_at (input_location, OPT_Wshadow,
+ warned = warning_at (input_location, warning_code,
"declaration of %qD shadows a previous local",
x);
@@ -3399,6 +3421,12 @@ do_class_using_decl (tree scope, tree name)
return NULL_TREE;
}
}
+ else if (name == ctor_identifier
+ && BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo)))
+ {
+ error ("cannot inherit constructors from indirect base %qT", scope);
+ return NULL_TREE;
+ }
else if (!name_dependent_p)
{
decl = lookup_member (binfo, name, 0, false, tf_warning_or_error);