Bug 82734 - -Wignored-qualifiers is maybe too strict when using decltype
Summary: -Wignored-qualifiers is maybe too strict when using decltype
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-26 12:38 UTC by Sylvestre Ledru
Modified: 2018-02-02 14:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvestre Ledru 2017-10-26 12:38:35 UTC
With the following code:
#include <stdint.h>
#include <assert.h>

void foo() {
  const int BLOCK_SIZE = 42;
  static_assert(
    BLOCK_SIZE <
      static_cast<decltype(BLOCK_SIZE)>(INT32_MAX));
}

----
# g++-7 -c -Wall -Wignored-qualifiers foo.cpp
# g++-8 -c -Wall -Wignored-qualifiers foo.cpp
foo.cpp: In function 'void foo()':
foo.cpp:9:50: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
       static_cast<decltype(BLOCK_SIZE)>(INT32_MAX));
                                                  ^
----

Either:
* The warning is too strict. In some cases, I don't control what BLOCK_SIZE can be and the const isn't a big deal
* I should have in the warning the definition of BLOCK_SIZE to have an idea of what is going on.
Comment 1 Andrew Pinski 2017-10-27 05:29:04 UTC
Why can't you use std::remove_cv<decltype(BLOCK_SIZE)> here?
Comment 2 Sylvestre Ledru 2017-10-27 17:18:25 UTC
I could, the code would be just more complex for no gain.

Just like with bug 82711, gcc is way too careful here and the warning is just adding noise.
Comment 3 Sylvestre Ledru 2018-02-02 14:51:18 UTC
For people who are getting these error, we fixed it with:
static_cast<std::remove_cv<decltype(MediaCacheStream::BLOCK_SIZE)>::type>(INT32_MAX)