简体   繁体   中英

no warnings in QT creator

I can't see almost any warnings in my program.

My cpp file:

#include <iostream>

using namespace std;

int main()
{
    long long int ll = 100000000067;
    unsigned short sh = ll; //no warning here, why?

    cout << sh << " " << ll << endl;


    int s;  //warning only here: warning: unused variable ‘s’ [-Wunused-variable]

    return 0;
}

My pro file:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

QMAKE_CXXFLAGS += -Wall -Wextra -pedantic

I try use project with cmake, but the results are this same.

According to GCC documentation

-Wconversion

Warn for implicit conversions that may alter a value. This includes conversions between real and integer, like abs (x) when x is double; conversions between signed and unsigned, like unsigned ui = -1; and conversions to smaller types, like sqrtf (M_PI). Do not warn for explicit casts like abs ((int) x) and ui = (unsigned) -1, or if the value is not changed by the conversion like in abs (2.0). Warnings about conversions between signed and unsigned integers can be disabled by using -Wno-sign-conversion. For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that never use a type conversion operator: conversions to void, the same type, a base class or a reference to them. Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

For me your example with -Wconversion generates

~/main.cpp:9: warning: conversion to 'short unsigned int' from 'long long int' may alter its value [-Wconversion]
   unsigned short sh = ll; //no warning here, why?
                       ^ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM