aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-decl.c
diff options
context:
space:
mode:
authorBernd Schmidt <bernds@redhat.com>2016-10-07 12:21:55 +0000
committerBernd Schmidt <bernds@gcc.gnu.org>2016-10-07 12:21:55 +0000
commit8a14afd0657b21e1de31fd1b2146056b09dbab5b (patch)
tree789ca4cb57ff3dbdcb638df0d2d1332b46093ad5 /gcc/c/c-decl.c
parent1edfde32a81006b564eb290a5989f473ab2d9af9 (diff)
downloadgcc-8a14afd0657b21e1de31fd1b2146056b09dbab5b.zip
gcc-8a14afd0657b21e1de31fd1b2146056b09dbab5b.tar.gz
gcc-8a14afd0657b21e1de31fd1b2146056b09dbab5b.tar.bz2
re PR c++/69733 (-Wignored-qualifiers points to wrong const)
c/ PR c++/69733 * c-decl.c (smallest_type_quals_location): New static function. (grokdeclarator): Try to find the correct location for an ignored qualifier. cp/ PR c++/69733 * decl.c (grokdeclarator): Try to find the correct location for an ignored qualifier. testsuite/ PR c++/69733 * c-c++-common/pr69733.c: New test. * gcc.dg/pr69733.c: New test. * gcc.target/i386/pr69733.c: New test. From-SVN: r240863
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r--gcc/c/c-decl.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 9e32be2..136f304 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5448,6 +5448,27 @@ warn_defaults_to (location_t location, int opt, const char *gmsgid, ...)
va_end (ap);
}
+/* Returns the smallest location != UNKNOWN_LOCATION in LOCATIONS,
+ considering only those c_declspec_words found in LIST, which
+ must be terminated by cdw_number_of_elements. */
+
+static location_t
+smallest_type_quals_location (const location_t *locations,
+ const c_declspec_word *list)
+{
+ location_t loc = UNKNOWN_LOCATION;
+ while (*list != cdw_number_of_elements)
+ {
+ location_t newloc = locations[*list];
+ if (loc == UNKNOWN_LOCATION
+ || (newloc != UNKNOWN_LOCATION && newloc < loc))
+ loc = newloc;
+ list++;
+ }
+
+ return loc;
+}
+
/* Given declspecs and a declarator,
determine the name and type of the object declared
and construct a ..._DECL node for it.
@@ -6262,7 +6283,19 @@ grokdeclarator (const struct c_declarator *declarator,
qualify the return type, not the function type. */
if (type_quals)
{
- int quals_used = type_quals;
+ const enum c_declspec_word ignored_quals_list[] =
+ {
+ cdw_const, cdw_volatile, cdw_restrict, cdw_address_space,
+ cdw_atomic, cdw_number_of_elements
+ };
+ location_t specs_loc
+ = smallest_type_quals_location (declspecs->locations,
+ ignored_quals_list);
+ if (specs_loc == UNKNOWN_LOCATION)
+ specs_loc = declspecs->locations[cdw_typedef];
+ if (specs_loc == UNKNOWN_LOCATION)
+ specs_loc = loc;
+
/* Type qualifiers on a function return type are
normally permitted by the standard but have no
effect, so give a warning at -Wreturn-type.
@@ -6272,13 +6305,14 @@ grokdeclarator (const struct c_declarator *declarator,
DR#423 means qualifiers (other than _Atomic) are
actually removed from the return type when
determining the function type. */
+ int quals_used = type_quals;
if (flag_isoc11)
quals_used &= TYPE_QUAL_ATOMIC;
if (quals_used && VOID_TYPE_P (type) && really_funcdef)
- pedwarn (loc, 0,
+ pedwarn (specs_loc, 0,
"function definition has qualified void return type");
else
- warning_at (loc, OPT_Wignored_qualifiers,
+ warning_at (specs_loc, OPT_Wignored_qualifiers,
"type qualifiers ignored on function return type");
/* Ensure an error for restrict on invalid types; the