public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code
@ 2014-12-28 22:02 rutsky.vladimir at gmail dot com
  2014-12-28 22:04 ` [Bug c++/64431] " rutsky.vladimir at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rutsky.vladimir at gmail dot com @ 2014-12-28 22:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

            Bug ID: 64431
           Summary: "-Wignored-qualifiers" warning gives misleading
                    position in code
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rutsky.vladimir at gmail dot com

"type qualifiers ignored on function return type" warning doesn't point in
"const" that is being ignored, but instead it points to function arguments or
function qualifiers.

Consider following example:

$ cat ignored_qualifiers.cpp
struct C
{
    const int f1();
    const int f2(float);
    const int f3(char *, int);
    const int f4() volatile const;
    const int f5() const volatile;
};

const int f6();
const int f7(float);
const int f8(char *, int);


$ g++-4.9 -c -Wignored-qualifiers ignored_qualifiers.cpp
ignored_qualifiers.cpp:3:18: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f1();
                  ^
ignored_qualifiers.cpp:4:23: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f2(float);
                       ^
ignored_qualifiers.cpp:5:29: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f3(char *, int);
                             ^
ignored_qualifiers.cpp:6:29: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f4() volatile const;
                             ^
ignored_qualifiers.cpp:7:26: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f5() const volatile;
                          ^
ignored_qualifiers.cpp:10:14: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
 const int f6();
              ^
ignored_qualifiers.cpp:11:19: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
 const int f7(float);
                   ^
ignored_qualifiers.cpp:12:25: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
 const int f8(char *, int);
                         ^


Expected behavior: the warning should point on "const" in the return value of a
funtion.
For example:


ignored_qualifiers.cpp:7:26: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]
     const int f5() const volatile;
     ^



$ g++-4.9 --version
g++-4.9 (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/64431] "-Wignored-qualifiers" warning gives misleading position in code
  2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
@ 2014-12-28 22:04 ` rutsky.vladimir at gmail dot com
  2014-12-29  1:50 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rutsky.vladimir at gmail dot com @ 2014-12-28 22:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

--- Comment #1 from Vladimir Rutsky <rutsky.vladimir at gmail dot com> ---
$ g++-4.9 -v
Using built-in specs.
COLLECT_GCC=g++-4.9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.9.2-0ubuntu1~14.04' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.9 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.2 (Ubuntu 4.9.2-0ubuntu1~14.04)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/64431] "-Wignored-qualifiers" warning gives misleading position in code
  2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
  2014-12-28 22:04 ` [Bug c++/64431] " rutsky.vladimir at gmail dot com
@ 2014-12-29  1:50 ` manu at gcc dot gnu.org
  2015-01-31  1:10 ` eugene.zelenko at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2014-12-29  1:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-29
                 CC|                            |manu at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
This is a problem also in C, however, in C++ it is trivial to fix:

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c       (revision 218749)
+++ gcc/cp/decl.c       (working copy)
@@ -9686,11 +9686,11 @@ grokdeclarator (const cp_declarator *dec
               Make sure we have a valid type for the function to return.  */

            if (type_quals != TYPE_UNQUALIFIED)
              {
                if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))
-                 warning (OPT_Wignored_qualifiers,
+                 warning_at (declspecs->locations[ds_const],
OPT_Wignored_qualifiers,
                           "type qualifiers ignored on function return type");
                /* We now know that the TYPE_QUALS don't apply to the
                   decl, but to its return type.  */
                type_quals = TYPE_UNQUALIFIED;
              }

I would suggest to add a testcase with explicit column numbers.

I added this to the list of EasyHacks and I'll leave it to a new dev to fix it
(see
https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps
if you want to be the one)
>From gcc-bugs-return-471828-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Dec 29 02:09:38 2014
Return-Path: <gcc-bugs-return-471828-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 1397 invoked by alias); 29 Dec 2014 02:09:37 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 1046 invoked by uid 48); 29 Dec 2014 02:09:25 -0000
From: "sandra at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/64377] nios2 compile error in options-save.c
Date: Mon, 29 Dec 2014 02:09:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: build
X-Bugzilla-Severity: normal
X-Bugzilla-Who: sandra at codesourcery dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc assigned_to
Message-ID: <bug-64377-4-zZWeakAStL@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64377-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64377-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-12/txt/msg02835.txt.bz2
Content-length: 607

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd377

Sandra Loosemore <sandra at codesourcery dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at ucw dot cz
           Assignee|sandra at codesourcery dot com     |unassigned at gcc dot gnu.org

--- Comment #3 from Sandra Loosemore <sandra at codesourcery dot com> ---
This has been discussed on the gcc-patches mailing list in this thread:

https://gcc.gnu.org/ml/gcc-patches/2014-11/msg02616.html


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/64431] "-Wignored-qualifiers" warning gives misleading position in code
  2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
  2014-12-28 22:04 ` [Bug c++/64431] " rutsky.vladimir at gmail dot com
  2014-12-29  1:50 ` manu at gcc dot gnu.org
@ 2015-01-31  1:10 ` eugene.zelenko at gmail dot com
  2015-03-05  9:40 ` paolo.carlini at oracle dot com
  2015-03-05 17:51 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: eugene.zelenko at gmail dot com @ 2015-01-31  1:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

Eugene Zelenko <eugene.zelenko at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eugene.zelenko at gmail dot com

--- Comment #3 from Eugene Zelenko <eugene.zelenko at gmail dot com> ---
Same problem exists in 4.8.2 and 4.8.3 and probably earlier versions.

Will be good idea to fix problem there too.

Eugene.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/64431] "-Wignored-qualifiers" warning gives misleading position in code
  2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
                   ` (2 preceding siblings ...)
  2015-01-31  1:10 ` eugene.zelenko at gmail dot com
@ 2015-03-05  9:40 ` paolo.carlini at oracle dot com
  2015-03-05 17:51 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-05  9:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|rutsky.vladimir at gmail dot com   |
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Mine.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/64431] "-Wignored-qualifiers" warning gives misleading position in code
  2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
                   ` (3 preceding siblings ...)
  2015-03-05  9:40 ` paolo.carlini at oracle dot com
@ 2015-03-05 17:51 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-05 17:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64431

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Note that, besides the cases of volatile and restrict which should be also
included, already have a patch including those, we need further tweaks to
recover the location of 'const' in:

   int* const f9();


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-05 17:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-28 22:02 [Bug c++/64431] New: "-Wignored-qualifiers" warning gives misleading position in code rutsky.vladimir at gmail dot com
2014-12-28 22:04 ` [Bug c++/64431] " rutsky.vladimir at gmail dot com
2014-12-29  1:50 ` manu at gcc dot gnu.org
2015-01-31  1:10 ` eugene.zelenko at gmail dot com
2015-03-05  9:40 ` paolo.carlini at oracle dot com
2015-03-05 17:51 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).