QT Creator 中没有警告

no warnings in QT creator

我在我的程序中几乎看不到任何警告。

我的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;
}

我的专业档案:

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

SOURCES += main.cpp

QMAKE_CXXFLAGS += -Wall -Wextra -pedantic

我尝试将项目与 cmake 一起使用,但结果是一样的。

根据 GCC 文档

-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.

对我来说,您使用 -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?
                       ^