简体   繁体   English

QT创建者中没有警告

[英]no warnings in QT creator

I can't see almost any warnings in my program. 我的程序几乎看不到任何警告。

My cpp file: 我的cpp文件:

#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. 我尝试将项目与cmake一起使用,但是结果是一样的。

According to GCC documentation 根据海湾合作委员会文件

-Wconversion -Wconversion

Warn for implicit conversions that may alter a value. 警告可能会更改值的隐式转换。 This includes conversions between real and integer, like abs (x) when x is double; 这包括实数和整数之间的转换,例如x为双精度时的abs(x); conversions between signed and unsigned, like unsigned ui = -1; 有符号和无符号之间的转换,例如unsigned ui = -1; and conversions to smaller types, like sqrtf (M_PI). 并转换为较小的类型,例如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). 不要警告像abs((int)x)和ui =(unsigned)-1之类的显式强制转换,或者不要像abs(2.0)中那样通过转换未更改该值。 Warnings about conversions between signed and unsigned integers can be disabled by using -Wno-sign-conversion. 可以使用-Wno-sign-conversion禁用有关有符号和无符号整数之间转换的警告。 For C++, also warn for confusing overload resolution for user-defined conversions; 对于C ++,还警告用户定义的转换会混淆重载分辨率。 and conversions that never use a type conversion operator: conversions to void, the same type, a base class or a reference to them. 以及从未使用类型转换运算符的转换:转换为void,相同类型,基类或对其的引用。 Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled. 除非显式启用了-Wsign-conversion,否则在C ++中默认禁用有关有符号和无符号整数之间转换的警告。

For me your example with -Wconversion generates 对我来说, -Wconversion的示例生成

~/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?
                       ^ 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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