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

            Bug ID: 91083
           Summary: inconsistent -Wsign-compare warnings
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: karol.wozniak at linuxmail dot org
  Target Milestone: ---

following code sample

template <typename T>
struct numeric_limits;

template<>
struct numeric_limits<long>
{
    static constexpr long
                max() noexcept { return 0x7fffffffffffffffL; }
};

int main() {
        return 42ul > numeric_limits<long>::max();
}

compiled with: g++-9 prog.cc -Wall -Wextra
raises sign-compare warning (https://wandbox.org/permlink/zW28qdCjM3hHPtMd)

but...
- adding optimization: g++-9 prog.cc -Wall -Wextra -O2 -march=native
removes the warning (https://wandbox.org/permlink/Z0GpP3JvunbpKqwO)
- creating helper value to store numeric_limit turns on warning once again in
optimized code (https://wandbox.org/permlink/94s4PEuJLlhKviye)

int main() {
    auto m = numeric_limits<long>::max();
        return 42ul > m;
}

- making helper value const... removes warning
(https://wandbox.org/permlink/Z0GpP3JvunbpKqwO)

warning was not raised in gcc-8 (https://wandbox.org/permlink/3yKmF2OVJ3FBIPye)

Reply via email to