Pedantic gcc warning: type qualifiers on function return type

前端 未结 8 534
名媛妹妹
名媛妹妹 2020-12-08 06:07

When I compiled my C++ code with GCC 4.3 for the first time, (after having compiled it successfully with no warnings on 4.1, 4.0, 3.4 with the -Wall -Wextra opt

8条回答
  •  春和景丽
    2020-12-08 06:45

    This warning is also useful to avoid confusion when declaring functions returning pointers to objects which should not be modified:

    // "warning: type qualifiers ignored on function return type"
    // as the pointer is copied. 
    Foo* const bar();
    
    // correct:
    const Foo* bar();
    

提交回复
热议问题