Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:45:02+00:00 2026-06-17T17:45:02+00:00

GCC (4.7.2) with -Wextra signals the following warning/error (I have -Werror enabled): Comparison is

  • 0

GCC (4.7.2) with -Wextra signals the following warning/error (I have -Werror enabled):

Comparison is always true due to limited range of data type [-Wtype-limits]

for the following code [try online]:

template <
    typename T,
    std::size_t N,
    bool = static_cast<std::size_t>(std::numeric_limits<T>::max()) < N>
struct validator {
    static constexpr bool validate(T value) {
        return static_cast<std::size_t>(value) < N;
    }
};

template <typename T, std::size_t N>
struct validator<T, N, true> {
    static constexpr bool validate(T) {
        return true;
    }
};

int main() {
    // Works
    static_assert(validator<int, 4>::validate(3), "Invalid");
    // Error :-(
    static_assert(validator<bool, 2>::validate(true), "Invalid");
}

I understand why the warning would occur in a normal expression context, e.g. when I would have used the following validate function:

template <typename T, std::size_t N>
bool validate(T value) {
    return static_cast<std::size_t>(value) < N;
}

– In fact, that’s why I am using the specialised template in the first place (and note that the correct template specialisation is used, and the error in my first code is raised by the template argument, not inside the function in the unspecialised template). Is there a way around this warning? If not, isn’t that a bug in the compiler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:45:03+00:00Added an answer on June 17, 2026 at 5:45 pm

    This has been fixed in GCC trunk, see PR 11856

    So wait for approximately late April and use GCC 4.8 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.5.1 c89 compiling with the following flags: -Wall, -Wextra I have the following
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,
gcc 4.1.2 c99 I have the following enum's in this file ccsmd.h : enum
gcc 4.4.2 c89 I have the following enum: enum drop_options_e { drop_ssm, drop_snm, drop_ssb
gcc 4.4.4 I have the following Makefile OBJECT_FILES = brd.o logger.o test_brd.o CFLAGS =
gcc 4.4.1 c89 I have the following code: static enum states { ACTIVE, RUNNING,
I'm reading the gcc manual at the moment, especially the part about warning/error flags.
gcc 4.7.2 c89 Hello, I am getting the following warning: pointer/integer type mismatch in
I have been advised to use the following options with GCC, as it helps
With GCC, when the -Wall -Wextra flags are enabled, one has the option of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.