警告:声明不会声明任何内容

时间:2009-05-19 01:31:41

标签: c++ iphone objective-c xcode

我在XCode中的一些功能完善的Objective-c代码中得到了这个警告。我的google-fu让我失望了......其他人已经碰到了这个但是我找不到关于究竟是什么导致它或如何修复它的解释。

4 个答案:

答案 0 :(得分:3)

在纯C中,代码如下:

int;
typedef int;

在没有设置警告选项的情况下从GCC引出以下警告:

x.c:1: warning: useless keyword or type name in empty declaration
x.c:1: warning: empty declaration
x.c:2: warning: useless keyword or type name in empty declaration
x.c:2: warning: empty declaration

也许你的代码中有类似的东西?

答案 1 :(得分:3)

发现问题并修复它。我有这个:

enum eventType { singleTouch };
enum eventType type;

...并将其更改为:

enum eventType { singleTouch } type;

答案 2 :(得分:0)

我能够使用以下代码复制此错误:

#define MY_INT int;
MY_INT a;

它编译删除';'在#define行。

答案 3 :(得分:0)

自Google将我带到这里以来,要在列表中再添加一个:此警告也可能在using声明中出现多余的“ typename”:

using SomeType = typename SomeNamespace::SomeType;

SomeType不是从属类型。

在进行一些重构以将模板类之外的“ SomeType”提升到命名空间范围以节省嵌入式C ++环境中的内存之后,我进入了这种情况。原始实现:

namespace SomeNamespace {
    template <typename T>
    SomeClass
    {
    public:
        enum class SomeType
        {
            A,
            B,
        };
        ...
    };
} //namespace SomeNamespace
...
void someFunction()
{
    using SomeType = typename SomeNameSpace::SomeClass<uint8_t>::SomeType;
    //typename is required above to resolve dependent scope
    ...
}

我重构为以下内容,但忘记删除someFunction中的“类型名”:

namespace SomeNamespace {
    // Now elevated to namespace scope so it is clear to the compiler that it does
    //    not need to be created for every template type of the class. While most
    //    compilers may be able to figure this one out easily, mine couldn't based
    //    on the optimization settings I need to use for my embedded project.
    enum class SomeType
    {
        A,
        B,
    };

    template <typename T>
    SomeClass
    {
    public:
        ...
    };
} //namespace SomeNamespace
...
void someFunction()
{
    using SomeType = **typename** SomeNameSpace::SomeType;
    //typename is no longer needed, but its removal was missed during refactoring
    ...
}

也许其他一些随机旅行者将降落在这里,并为他们节省了15分钟的时间,以便他们尝试理解此警告的含义。

相关问题