【问题标题】:no warning is given for a deprecated beheavior in c++11c++11中不推荐使用的行为没有警告
【发布时间】:2015-04-07 02:43:24
【问题描述】:

根据cppreference

隐式定义的复制构造函数的生成是 如果 T 具有用户定义的析构函数或用户定义的副本,则不推荐使用 赋值运算符。

但是下面的代码,使用clang++和c++没有给出警告信息

struct CAT
{
    CAT(){cout<<"CAT()"<<endl;}
    ~CAT(){}
};

int main()
{
    CAT c1, c2;
    CAT c3(c1); //should print out a warning?
}

clang++-3.6  -W -Wall -Wextra -pedantic  -O2 -o m main.cpp -pedantic-errors -std=c++14

这是 g++ 和 clang++ 的预期行为吗?

【问题讨论】:

    标签: c++11 g++ clang++


    【解决方案1】:

    clang++ 有这个警告:

    main.cpp:6:5: warning: definition of implicit copy constructor for 'CAT' is deprecated because it has a user-declared destructor [-Wdeprecated]
        ~CAT(){}
        ^
    main.cpp:12:9: note: implicit copy constructor for 'CAT' first required here
        CAT c3(c1); //should print out a warning?
            ^
    1 warning generated.
    

    演示:http://coliru.stacked-crooked.com/a/d6b31ce2d56fac5a

    【讨论】:

    • 我在ubuntu clang++/g++ -Wdeprecated -o test -std=c++14 -O3 -pedantic-errors main.cpp (clang++3.6, g++4.8.2 ),但没有警告。
    猜你喜欢
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2023-03-11
    • 1970-01-01
    • 2020-02-23
    • 2019-09-21
    • 2016-09-19
    相关资源
    最近更新 更多