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

  • Home
  • SEARCH
  • 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 8330603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:10:21+00:00 2026-06-09T02:10:21+00:00

const auto min = -std::numeric_limits<T>::max(); T x = min; // conversion from ‘const int’

  • 0
const auto min = -std::numeric_limits<T>::max();
T x = min; // conversion from 'const int' to 'short', possible loss of data

T is a template argument, a short in this case. Unary minus apparently performs integral promotion.

  • Why does unary minus perform integral promotion?
  • If auto is changed to T no warning is generated, but it should be assigning an int to a short. Why isn’t there a warning (it could be VS being fancy)?
  • 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-09T02:10:23+00:00Added an answer on June 9, 2026 at 2:10 am

    Short answer: (now long because people want to be excessively pedantic about English which by its very nature is not exact).

    Its not explicitly (as in the unary minus mathematical).
    But as part of any operation (this includes unary minus operation) on POD data there is an implicit check on input parameters (the smallest integer type that can be used in and operation is int) so there is integral promotion on the input before the unary minus (the mathematical part not the operation part). The output of all operations on POD is the same as the input parameters (after integral promotion is applied). Thus here the output is also an int.

    Long answer:

    In C (and thus C++) the smallest type that POD operations happen on is int. So before the unary minus is applied the value is converted to int. Then the unary minus is applied. The result of the expression is thus int.

    See here: Implicit type conversion rules in C++ operators

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

Sidebar

Related Questions

#include <functional> #include <iostream> namespace{ //const std::function< void( const int ) > foo[] =
const size_t size = 5; int *i = new int[size](); for (int* k =
const (and in ) Consider there is C function: unsigned int foo(const unsigned int
I have a const int that is computed at compile time in my Managed
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;
Declarations of auto_ptr from C++ Standard Library namespace std { template <class Y> struct
Is there a semantic difference between auto const and const auto , or do
static const map<const Type*, int>* priority; where Type is my own special class. Initialization
I think the question is clear enough. Will the auto keyword auto-detect const-ness, or
Variant a: const auto end = whatever.end(); for (auto it = whatever.begin(); it !=

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.